<template>
  <div class="app-container">
    <template>
      <div class="right-detail">
        <div class="form">
          <el-form ref="form" :model="form" :rules="rule" :inline="true" size="mini">
            <el-form-item label="合同号:">
              <el-input v-model="form.cmtContractNo" clearable style="width: 200px" placeholder="请输入"></el-input>
            </el-form-item>
            <el-form-item label="签订状态:">
              <el-select v-model="form.cmtContractState" filterable clearable placeholder="请选择" style="width: 200px">
                <el-option v-for="item in contractStates" :key="item.code" :value="item.code" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="合同类型:">
              <el-select v-model="form.cmtContractType" filterable clearable placeholder="请选择" style="width: 200px">
                <el-option v-for="item in cmtContractType" :key="item.rvLowValue" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="运输方式:">
              <el-select v-model="form.cmtShippingType" filterable clearable placeholder="请选择" style="width: 200px">
                <el-option v-for="item in shippingType" :key="item.rvLowValue" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="托运人:">
              <!-- <el-input v-model="form.cmtPartyAName" clearable style="width:180px"></el-input> -->
              <el-select v-model="form.cmtPartyAName" filterable clearable allow-create default-first-option style="width: 100%">
                <el-option v-for="item in jfdropdown" :key="item.code" :value="item.name" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="承运人:">
              <!-- <el-input v-model="form.cmtPartyBName" clearable style="width:180px"></el-input> -->
              <el-select v-model="form.cmtPartyBName" filterable clearable allow-create default-first-option style="width: 100%">
                <el-option v-for="item in efdropdown" :key="item.code" :value="item.name" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="start" label="签订时间:">
              <el-date-picker v-model="form.start" value-format="yyyy-MM-dd" style="width: 180px" placeholder="请选择开始时间"></el-date-picker>
            </el-form-item>
            <el-form-item prop="end" label-width="3em" label="——">
              <el-date-picker v-model="form.end" value-format="yyyy-MM-dd" style="width: 180px" placeholder="请选择结束时间"></el-date-picker>
            </el-form-item>
            <el-form-item prop label>
              <el-button type="primary" size="mini" @click="search">查 询</el-button>
            </el-form-item>
          </el-form>
        </div>
        <split-pane split="horizontal" v-on:resize="resize" :default-percent="55" :max-percent="80">
          <!-- 上半部分 -->
          <template slot="paneL">
            <div class="top-type" ref="topType">
              <div class="btn-area" ref="btnArea" style="padding-left: 13px">
                <el-row :gutter="24">
                  <!-- <el-col :span="12"> -->
                  <buttonName @clickEvent="clickEventDom"></buttonName>
                  <!-- <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="!supplier && isAuth('addContract')"
                      @click="addCar"
                    >新增合同</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="!supplier && isAuth('editContract')"
                      @click="editCar"
                    >编辑合同</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="!supplier && isAuth('delContract')"
                      @click="delCar"
                    >删除合同</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="isAuth('downloadContract')"
                      @click="downloadDialog('doc')"
                    >下载合同</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="isAuth('printContract')"
                      @click="downloadDialog('html')"
                    >打印合同</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="isAuth('sign')"
                      @click="effective2()"
                    >签订</el-button>
                    <el-button
                      plain
                      size="mini"
                      type="primary"
                      v-if="isAuth('back')"
                      @click="goback()"
                  >驳回</el-button>-->
                  <!-- </el-col> -->
                  <el-col :span="5" :offset="6" v-if="expire">
                    <el-tag effect="dark" style="width: 52px; background: red; border-color: red; height: 15px; border-radius: 0px"></el-tag>
                    <el-tag effect="dark" style="background-color: #eff2f500; border-color: #f3f3f300; color: #060606">
                      <p>三天后到期</p>
                    </el-tag>
                  </el-col>
                </el-row>
              </div>
              <div class="table" ref="inner">
                <el-table
                  :data="tableData"
                  border
                  class="demand"
                  :height="typeHeight"
                  :header-cell-style="{ textAlign: 'center' }"
                  highlight-current-row
                  @row-click="rowClick"
                  @row-dblclick="dbrowClick"
                  :cell-style="cellStyle"
                  :reserve-selection="true"
                  :row-key="getRowKeys"
                  ref="multipleTable"
                  @selection-change="handleSelectionChange"
                >
                  <drag-table-header :data="$data" :table-header="tableHeader"></drag-table-header>
                  <!-- <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
                  <el-table-column type="selection" width="55"></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtContractState"
                    label="签订状态"
                    show-overflow-tooltip
                    width="120"
                    sortable
                  >
                    <template slot-scope="scope">
                      <p v-if="scope.row.cmtContractState=='0'">未签订</p>
                      <p v-if="scope.row.cmtContractState=='2'">已生成订单计划</p>
                      <p v-if="scope.row.cmtContractState=='3'">待确定</p>
                      <p v-if="scope.row.cmtContractState=='4'">终止待确认</p>
                      <p v-if="scope.row.cmtContractState=='5'">已终止</p>
                      <p v-if="scope.row.cmtContractState=='6'">被驳回</p>
                      <p
                        v-if="scope.row.cmtContractState!='0' && scope.row.cmtContractState!='2'&& scope.row.cmtContractState!='3'
                         && scope.row.cmtContractState!='4' && scope.row.cmtContractState!='5'&& scope.row.cmtContractState!='6'"
                      >已签订</p>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtSigningTime"
                    label="签订时间"
                    show-overflow-tooltip
                    width="165"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtContractNo"
                    label="合同编号"
                    show-overflow-tooltip
                    width="165"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtContractName"
                    label="合同名称"
                    show-overflow-tooltip
                    width="150"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="cmtLineIsSign"
                    label="电子签章"
                    show-overflow-tooltip
                    width="110"
                    sortable
                  >
                    <template slot-scope="scope">
                      <el-checkbox
                        :value="scope.row.cmtLineIsSign=='Y'?true:false"
                        :disabled="true"
                      ></el-checkbox>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtContractTypeName"
                    label="合同类型"
                    show-overflow-tooltip
                    width="150"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtPartyAName"
                    label="托运人"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtPartyBName"
                    label="承运人"
                    show-overflow-tooltip
                    width="120"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtPartyAContacts"
                    label="托运人联系人"
                    show-overflow-tooltip
                    width="150"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtPartyAPhone"
                    label="托运人联系电话"
                    show-overflow-tooltip
                    width="150"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtPartyBContacts"
                    label="承运人联系人 "
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtPartyBPhone"
                    label="承运人联系电话"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="right"
                    prop="cmtConsigneeInformation"
                    label="目的地收货人"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtPlaceReceipt"
                    label="收货地点"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtReceivingContact"
                    label="收货联系人"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtReceivingPhone"
                    label="收货人联系电话"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtLoadingPlace"
                    label="装货地点"
                    show-overflow-tooltip
                    width="140"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtLoadingContact"
                    label="装货地点联系方式"
                    show-overflow-tooltip
                    width="180"
                    sortable
                  ></el-table-column>

                  <el-table-column
                    align="left"
                    prop="cmtPackingMethodName"
                    label="包装方式"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="cmtSingleWeightName"
                    label="单件重量"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtShippingType"
                    label="运输方式"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="cmtTransportUnitPrice"
                    label="运输单价"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtTotalFreight"
                    label="运费合计"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="center"
                    prop="cmtStartDateShipment"
                    label="承运起始日期"
                    show-overflow-tooltip
                    width="130"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtLatestLoadingDate"
                    label="最迟装货日期"
                    show-overflow-tooltip
                    width="140"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtCorporateName"
                    label="公司名称"
                    show-overflow-tooltip
                    width="120"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtOpeningBank"
                    label="开户行"
                    show-overflow-tooltip
                    width="120"
                    sortable
                  ></el-table-column>
                  <el-table-column
                    align="left"
                    prop="cmtAccount"
                    label="账号"
                    show-overflow-tooltip
                    width="120"
                    sortable
                  ></el-table-column> -->
                </el-table>
              </div>
              <div>
                <el-pagination
                  ref="pagination"
                  small
                  background
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="Pagination.currentPage"
                  :page-sizes="Pagination.pageSizeList"
                  :page-size="Pagination.pageSize"
                  :layout="Pagination.layout"
                  :total="Pagination.total"
                ></el-pagination>
              </div>
            </div>
          </template>
          <!-- 下半部分 -->
          <template slot="paneR">
            <div class="codeNumberCode" style="background-color: #fff">托运内容</div>
            <div class="bottom-code" ref="bottomCode" style="background-color: #fff">
              <div class="table">
                <!-- <el-collapse value="1"> -->
                <!-- <el-collapse-item title="托运内容" name="1"> -->
                <el-table :data="mainBotTableData" border :height="detlHeight" :header-cell-style="{ textAlign: 'center' }" highlight-current-row>
                  <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="提货单编号" prop="cddTakeNo"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="类别" prop="cddType"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="船公司" prop="cddShippingCompany"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="品牌" prop="cddBrand"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="等级/榨季/升贴水" prop="cddGrade"></el-table-column>
                  <el-table-column align="left" show-overflow-tooltip label="数量（吨）" prop="cddQuantity"></el-table-column>
                </el-table>
                <!-- </el-collapse-item> -->
                <!-- </el-collapse> -->
              </div>
            </div>
          </template>
        </split-pane>
      </div>
    </template>

    <!-- 对话框 新增 编辑合同管理 -->
    <el-dialog :title="name" :visible.sync="openDialog" v-el-drag-dialog :before-close="close" :close-on-click-modal="false" width="70%">
      <div class="dialogBox">
        <div class="dialogTopBox">
          <el-form :model="dialogForm" size="mini" :rules="dialogRule" ref="dialogForm" label-width="auto">
            <div class="box">
              <div class="name">基础信息</div>
              <el-row :gutter="24">
                <el-col :span="12">
                  <el-form-item prop="bidId" label="标书：">
                    <div
                      @click="see ? (RefTypeDialogVisible = false) : (RefTypeDialogVisible = true), (queryParam = {}), (querydemandParam = {}), BiddingList()"
                    >
                      <el-input
                        v-model="feeValue"
                        :class="{ pointerinput: !see }"
                        disabled
                        clearable
                        maxlength="32"
                        placeholder="选择标书"
                        ref="bidIdref"
                      ></el-input>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col :span="3">
                  <el-button
                    size="mini"
                    type="primary"
                    @click="see ? (RefTypeDialogVisible = false) : (RefTypeDialogVisible = true), (queryParam = {}), (querydemandParam = {}), BiddingList()"
                    >选择标书</el-button
                  >
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item prop="cmtContractNo" label="合同编号：">
                    <el-input v-model="dialogForm.cmtContractNo" style="width: 95%" clearable disabled="true" maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtContractName" label="合同名称：">
                    <el-input v-model="dialogForm.cmtContractName" style="width: 95%" :disabled="see" clearable maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtContractType" label="合同类型：">
                    <el-select v-model="dialogForm.cmtContractType" placeholder="请选择" :disabled="see" clearable style="width: 95%">
                      <el-option v-for="item in cmtContractType" :key="item.rvLowValue" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <!-- <el-col :span="8">
                <el-form-item prop="cmtGoodsName" label="货物品名：">
                  <el-input v-model="dialogForm.cmtGoodsName" style="width:95%"  clearable :disabled="see" maxlength="32">
                  </el-input>
                </el-form-item>
                </el-col>-->
                <el-col :span="8">
                  <el-form-item prop="cmtShippingType" label="运输方式：">
                    <el-input v-model="dialogForm.cmtShippingType" style="width: 95%" clearable :disabled="see" maxlength="10"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtPackingMethod" label="包装方式：">
                    <el-select v-model="dialogForm.cmtPackingMethod" placeholder="请选择" :disabled="see" clearable style="width: 95%">
                      <el-option v-for="item in modeList" :key="item.rvLowValue" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtSingleWeight" label="单件重量(公斤)：">
                    <el-select v-model="dialogForm.cmtSingleWeight" placeholder="请选择" filterable disabled style="width: 95%">
                      <el-option v-for="item in dailyOutputs" :key="item.normCode" :value="item.normCode" :label="item.normName"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="24">
                <el-col :span="8">
                  <el-form-item prop="cmtGoodsName" label="运输总量(吨)：">
                    <el-input v-model="dialogForm.cmtContractTotalTransport" style="width: 95%" clearable disabled="ture" maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtTransportUnitPrice" label="运输单价(元/吨)：">
                    <el-input
                      v-model="dialogForm.cmtTransportUnitPrice"
                      @change="calculationTotalFreight"
                      style="width: 95%"
                      :oninput="(dialogForm.cmtTransportUnitPrice = numberOnly(dialogForm.cmtTransportUnitPrice))"
                      clearable
                      :disabled="pricesee"
                      maxlength="9"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtTotalFreight" label="运费合计(元)：">
                    <el-input
                      v-model="dialogForm.cmtTotalFreight"
                      style="width: 95%"
                      :oninput="(dialogForm.cmtTotalFreight = numberOnly(dialogForm.cmtTotalFreight))"
                      clearable
                      :disabled="see"
                      maxlength="9"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item prop="cmtStartDateShipment" label="承运起始日期：">
                    <el-date-picker
                      style="width: 95%"
                      @change="cmtStartDateShipmentChange"
                      v-model="dialogForm.cmtStartDateShipment"
                      :disabled="see"
                      type="date"
                      placeholder="选择日期"
                      value-format="yyyy-MM-dd"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtLatestLoadingDate" label="最迟装货日期：">
                    <el-date-picker
                      style="width: 95%"
                      :picker-options="{ disabledDate }"
                      v-model="dialogForm.cmtLatestLoadingDate"
                      :disabled="see"
                      type="date"
                      placeholder="选择日期"
                      value-format="yyyy-MM-dd"
                    ></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否存在第三方：" prop="cmtIsthrid">
                    <el-radio-group v-model.trim="dialogForm.cmtIsthrid" @change="generateNo">
                      <el-radio :disabled="disabled" label="Y">是</el-radio>
                      <el-radio :disabled="disabled" label="N">否</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="2">
                  <el-form-item size="mini" label-width="20px">
                    <el-button size="mini" type="primary" @click="openUploadDialog" v-show="!filesee">附件上传</el-button>
                  </el-form-item>
                </el-col>
                <el-col :span="2">
                  <el-form-item size="mini" label-width="0px" style="margin-left: 20px">
                    <el-button size="mini" type="primary" v-show="!filesee" @click="viewFile">查看附件</el-button>
                  </el-form-item>
                </el-col>
                <el-col :span="2">
                  <el-form-item size="mini" label-width="0px">
                    <el-button size="mini" type="primary" v-show="eContractSee" @click="viewContract">查看电子合同</el-button>
                  </el-form-item>
                </el-col>
                <el-col :span="2">
                  <el-form-item size="mini" label-width="0px">
                    <el-button size="mini" type="primary" v-show="eContractSee" @click="downContract">下载电子合同</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>

            <el-row :gutter="24">
              <el-col :span="12">
                <div class="box">
                  <div class="name">托运方信息</div>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyA" label="托运方：">
                        <el-select v-model="dialogForm.cmtPartyA" @change="generateNo" placeholder="请选择" filterable :disabled="see" style="width: 95%">
                          <el-option v-for="item in jfdropdown" :key="item.code" :value="item.code" :label="item.name"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyAContacts" label="托运方联系人：">
                        <el-input v-model="dialogForm.cmtPartyAContacts" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyAPhone" label="托运方联系电话：">
                        <el-input
                          v-model="dialogForm.cmtPartyAPhone"
                          style="width: 95%"
                          :oninput="(dialogForm.cmtPartyAPhone = dialogForm.cmtPartyAPhone.replace(/[^\d]/g, ''))"
                          clearable
                          :disabled="see"
                          maxlength="11"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtLoadingPlace" label="装货地点：">
                        <el-input v-model="dialogForm.cmtLoadingPlace" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtConsigneeInformation" label="目的地收货方：">
                        <!-- <el-input
                          v-model="dialogForm.cmtConsigneeInformation"
                          style="width:95%"
                          clearable
                          :disabled="see"
                          maxlength="32"
                        ></el-input>-->
                        <el-select
                          v-model="dialogForm.cmtConsigneeInformation"
                          @change="bangding"
                          filterable
                          :disabled="see"
                          clearable
                          allow-create
                          default-first-option
                          style="width: 95%"
                        >
                          <!-- @change="bangding" -->
                          <el-option v-for="item in mddslist" :key="String(item.code)" :value="item.value" :label="item.value"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPlaceReceipt" label="收货地点：">
                        <el-input v-model="dialogForm.cmtPlaceReceipt" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtReceivingContact" label="收货联系人：">
                        <!-- <el-input
                          v-model="dialogForm.cmtReceivingContact"
                          style="width:95%"
                          clearable
                          :disabled="see"
                          maxlength="32"
                        ></el-input>-->
                        <el-select
                          v-model="dialogForm.cmtReceivingContact"
                          filterable
                          clearable
                          allow-create
                          :disabled="see"
                          default-first-option
                          style="width: 95%"
                        >
                          <el-option v-for="item in shlxrlist" :key="String(item.code)" :value="item.value" :label="item.value"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtReceivingPhone" label="收货人联系电话：">
                        <!-- <el-input
                          v-model="dialogForm.cmtReceivingPhone"
                          style="width:95%"
                          :oninput="dialogForm.cmtReceivingPhone=dialogForm.cmtReceivingPhone.replace(/[^\d]/g,'')"
                          clearable
                          :disabled="see"
                          maxlength="32"
                        ></el-input>-->
                        <el-select
                          v-model="dialogForm.cmtReceivingPhone"
                          filterable
                          :oninput="(dialogForm.cmtReceivingPhone = dialogForm.cmtReceivingPhone.replace(/[^\d]/g, ''))"
                          clearable
                          allow-create
                          :disabled="see"
                          default-first-option
                          style="width: 95%"
                        >
                          <el-option v-for="item in lxrphonelist" :key="String(item.code)" :value="item.value" :label="item.value"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
              <el-col :span="12">
                <div class="box">
                  <div class="name">承运方信息</div>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyB" label="承运方：">
                        <el-select v-model="dialogForm.cmtPartyB" placeholder="请选择" filterable @change="selectGys" :disabled="see" style="width: 95%">
                          <el-option v-for="item in efdropdown" :key="item.code" :value="item.code" :label="item.name"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyBContacts" label="承运方联系人：">
                        <el-input v-model="dialogForm.cmtPartyBContacts" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtPartyBPhone" label="承运方联系电话：">
                        <el-input
                          v-model="dialogForm.cmtPartyBPhone"
                          style="width: 95%"
                          :oninput="(dialogForm.cmtPartyBPhone = dialogForm.cmtPartyBPhone.replace(/[^\d]/g, ''))"
                          clearable
                          :disabled="see"
                          maxlength="11"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <el-form-item prop="cmtLoadingContact" label="装货地点联系方式：">
                        <el-input v-model="dialogForm.cmtLoadingContact" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <div class="grid-content"></div>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <div class="grid-content"></div>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <div class="grid-content"></div>
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="24">
                      <div class="grid-content"></div>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
            <div class="box">
              <div class="name">账户信息</div>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item prop="cmtCorporateName" label="公司名称：">
                    <el-input v-model="dialogForm.cmtCorporateName" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtOpeningBank" label="开户行：">
                    <el-input v-model="dialogForm.cmtOpeningBank" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item prop="cmtAccount" label="账号 ：">
                    <el-input v-model="dialogForm.cmtAccount" style="width: 95%" clearable :disabled="see" maxlength="32"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-form>
        </div>
        <div class="box">
          <div class="name">托运信息</div>
          <div class="dialogBotBox">
            <div class="botBtnBox">
              <!-- <el-button plain size="mini" type="primary" @click="addDataArray">新增</el-button>
              <el-button plain size="mini" type="primary" @click="delRow">删除</el-button>-->
            </div>
            <el-form :model="tableDataArray" ref="tableDataArray">
              <el-table
                :data="tableDataArray"
                ref="table_config_data_table"
                border
                row-key="id"
                align="left"
                @row-click="rowData"
                :row-class-name="tableRowClassName"
                :height="tableDataheight"
              >
                <el-table-column label="序号" type="index" width="50"></el-table-column>
                <el-table-column label="提货单编号">
                  <template slot-scope="scope">
                    <el-form-item :prop="scope.$index + '.cddTakeNo'">
                      <!-- :rules="[ {required: true, message: '提货单编号不能为空', trigger: 'blur'}]" -->
                      <el-input
                        v-model="tableDataArray[scope.$index].cddTakeNo"
                        :disabled="see"
                        maxlength="32"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="类别">
                  <template slot-scope="scope">
                    <el-form-item :prop="`${scope.$index}.cddType`">
                      <el-input
                        v-model="tableDataArray[scope.$index].cddType"
                        clearable
                        maxlength="32"
                        size="mini"
                        placeholder="请输入"
                        :disabled="see"
                      ></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="船公司">
                  <template slot-scope="scope">
                    <el-form-item :prop="scope.$index + '.cddShippingCompany'">
                      <!-- :rules="[ {required: true, message: '船公司不能为空', trigger: 'blur'}]" -->
                      <el-input
                        v-model="tableDataArray[scope.$index].cddShippingCompany"
                        maxlength="32"
                        :disabled="see"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="品牌">
                  <template slot-scope="scope">
                    <el-form-item :prop="scope.$index + '.cddBrand'" :rules="[{ required: true, message: '品牌不能为空', trigger: 'blur' }]">
                      <el-input
                        v-model="tableDataArray[scope.$index].cddBrand"
                        maxlength="32"
                        :disabled="see"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="等级/榨季/升贴水">
                  <template slot-scope="scope">
                    <el-form-item :prop="scope.$index + '.cddGrade'" :rules="[{ required: true, message: '不能为空', trigger: 'blur' }]">
                      <el-input
                        v-model="tableDataArray[scope.$index].cddGrade"
                        maxlength="32"
                        :disabled="see"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>
                      <!--<el-select-->
                      <!--  v-model="tableDataArray[scope.$index].cddGrade"-->
                      <!--  filterable-->
                      <!--  clearable-->
                      <!--  allow-create-->
                      <!--  size="mini"-->
                      <!--  :disabled="see"-->
                      <!--  default-first-option-->
                      <!--  style="width: 95%"-->
                      <!--&gt;-->
                      <!--  <el-option v-for="item in goodarr" :key="item.cddId" :value="item.cddGrade" :label="item.cddGrade"></el-option>-->
                      <!--</el-select>-->
                      <!-- <el-input
                        v-model="tableDataArray[scope.$index].cddGrade"
                        maxlength="32"
                        :disabled="see"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>-->
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="数量（吨）">
                  <template slot-scope="scope">
                    <el-form-item :prop="scope.$index + '.cddQuantity'" :rules="[{ required: true, validator: chckcddQuantity, trigger: 'blur' }]">
                      <el-input
                        v-model="tableDataArray[scope.$index].cddQuantity"
                        :disabled="see"
                        maxlength="9"
                        :oninput="(tableDataArray[scope.$index].cddQuantity = numberOnly(tableDataArray[scope.$index].cddQuantity))"
                        clearable
                        size="mini"
                        placeholder="请输入内容"
                      ></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
              </el-table>
            </el-form>
          </div>
        </div>
      </div>
      <!-- 选择标书弹出框-->
      <el-dialog
        width="50%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-el-drag-dialog
        title="选择标书"
        :visible.sync="RefTypeDialogVisible"
        v-if="RefTypeDialogVisible"
        :before-close="handleTypeDialogClose"
        append-to-body
      >
        <el-form class="form" :model="queryParam" ref="queryParam" :rules="rules" label-width="9rem" size="mini">
          <el-row :gutter="20" class="row">
            <el-col :span="8">
              <el-form-item size="mini" label="标的编号：" prop="bidCode" label-width="85px">
                <el-input clearable v-model="queryParam.bidCode" size="mini" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item size="mini" label="标的名称：" prop="bidName" label-width="100px">
                <el-input clearable v-model="queryParam.bidName" size="mini" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label-width="10px">
                <el-button @click="searchType" type="primary">查询</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          :data="biddingList"
          highlight-current-row
          border
          :height="biddingHeight"
          :header-cell-style="{
            textAlign: 'center',
          }"
          :cell-style="{}"
          @row-click="biddingClick"
        >
          <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="bidCode" align="center" label="标的编号"></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="bidName" align="center" label="标的名称"></el-table-column>
          <el-table-column align="center" label="标的状态" prop="bidStatus" show-overflow-tooltip></el-table-column>
          <el-table-column size="mini" show-overflow-tooltip prop="bidType" align="center" label="标的类型"></el-table-column>
        </el-table>
        <div class="tableTitle"></div>

        <div>
          <el-form class="form" :model="querydemandParam" label-width="9rem" size="mini">
            <el-row :gutter="20" class="row">
              <el-col :span="8">
                <el-form-item size="mini" label="需求编号：" prop="demandCode" label-width="85px">
                  <el-input clearable v-model="querydemandParam.demandCode" size="mini" style="width: 100%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item label-width="10px">
                  <el-button @click="searchDemand" type="primary">查询</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-table
            :data="contractSugarList"
            :height="detlHeight + 30"
            highlight-current-row
            border
            :header-cell-style="{
              textAlign: 'center',
            }"
            :cell-style="{}"
            @row-click="contractSugarClick"
          >
            <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip width="120" align="left" prop="demandCode" label="需求编号"></el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="brand" label="货物品牌"></el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="dailyOutput" label="规格"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip prop="product" align="center" label="产品大类"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip prop="kind" align="center" label="品种"></el-table-column>
            <el-table-column show-overflow-tooltip align="center" prop="transportQuantity" label="运输数量(吨)"></el-table-column>
            <!-- <el-table-column size="mini" show-overflow-tooltip prop="cmtContractNo"  align="center" label="合同编号" ></el-table-column> -->
            <el-table-column show-overflow-tooltip align="center" label="操作">
              <template>
                <el-button size="mini" type="primary" plain @click="tranDialogInfoDialogVisible = true">线路详情</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tableTitle">供应商信息</div>
        <div>
          <el-table
            :data="quotaDialogList"
            :height="detlHeight + 30"
            highlight-current-row
            border
            :header-cell-style="{
              textAlign: 'center',
            }"
            :cell-style="{}"
            @row-click="quotaDialogListClick"
          >
            <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip width="380" align="center" prop="usrName" label="供应商"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip prop="biddingPrice" align="center" label="运输单价(元/吨)"></el-table-column>
            <el-table-column size="mini" show-overflow-tooltip prop="bqTransportQuantity" align="center" label="运输总量(吨)"></el-table-column>
          </el-table>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click=";(RefTypeDialogVisible = false), (quotaDialogList = []), (quotaDialog = {})" size="mini">关闭</el-button>
          <el-button type="primary" @click="savebidding" size="mini">确定</el-button>
        </div>
        <el-dialog
          width="40%"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          v-el-drag-dialog
          title="线路详情"
          :visible.sync="tranDialogInfoDialogVisible"
          v-if="tranDialogInfoDialogVisible"
          append-to-body
        >
          <el-table
            :data="tranDialogInfoList"
            :height="detlHeight"
            highlight-current-row
            border
            :header-cell-style="{
              textAlign: 'center',
            }"
            :cell-style="{}"
          >
            <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
            <el-table-column show-overflow-tooltip align="center" label="起始地" prop="site"></el-table-column>
            <el-table-column show-overflow-tooltip align="center" label="目的地" prop="destination"></el-table-column>
          </el-table>
          <span slot="footer" class="dialog-footer">
            <el-button size="mini" type="primary" @click="tranDialogInfoDialogVisible = false">关闭</el-button>
          </span>
        </el-dialog>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close" size="mini">关闭</el-button>
        <el-button type="primary" @click="save" v-if="priceseeA" size="mini">保存</el-button>
        <el-button type="primary" @click="effective" v-if="!qdsee" size="mini">签订纸质合同</el-button>
        <el-button type="primary" @click="effective3" v-if="!qdsee" size="mini">签订电子合同</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="name"
      :visible.sync="downloadOpenDialog"
      v-if="downloadOpenDialog"
      v-el-drag-dialog
      :before-close="closeDownload"
      :close-on-click-modal="false"
      :width="downloadWidth"
    >
      <el-form
        size="mini"
        v-show="downloadType != 'template'"
        ref="dialogDownloadForm"
        :model="dialogDownloadForm"
        :rules="dialogDownloadFormRule"
        label-width="auto"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item prop="templateTvalue" label="选择模板：">
              <el-select v-model="dialogDownloadForm.templateTvalue" placeholder="请选择">
                <el-option v-for="item in templateList" :key="item.cteId" :label="item.cteName" :value="item.cteId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-collapse-transition>
        <div v-show="downloadType == 'template'">
          <div :style="templateObjec" v-show="downloadType == 'template'">
            <div ref="html_template" style="transform: scale(0.9) translateY(-12%)">
              <!-- 要打印的内容 -->
              <div id="printMe" v-html="html"></div>
            </div>
          </div>
        </div>
      </el-collapse-transition>
      <div slot="footer" class="dialog-footer">
        <el-button @click=";(downloadOpenDialog = false), refreshList()" size="mini">关闭</el-button>
        <el-button type="primary" @click="download" v-if="downloadType != 'template'" size="mini">确定</el-button>
        <!-- <el-button type="primary"  v-print="'#printMer'" v-if="downloadType == 'template'"  size="mini">打印</el-button> -->
        <el-button type="primary" @click="printContent" v-if="downloadType == 'template'" size="mini">打印</el-button>
      </div>
    </el-dialog>
    <!-- 附件上传 -->
    <el-dialog
      :title="uploadDialog.title"
      :visible.sync="uploadDialog.show"
      :close-on-click-modal="false"
      width="40%"
      style="padding: 0"
      @close="uploadDialogClose"
      v-el-drag-dialog
      v-dialogDrag
    >
      <div>
        <el-form ref="uploadFileFrom" :model="uploadFile" label-width="100px" :rules="uploadFileRules">
          <el-row>
            <el-col>
              <el-form-item label="文件名称：" prop="name">
                <el-input v-model="uploadFile.name" style="width: 80%" clearable maxlength="32"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="文件：" prop="file">
                <el-upload
                  class="upload-demo"
                  accept=".pdf, .png, .img, .jpeg, .jpg"
                  drag
                  action
                  limit="1"
                  :on-remove="removeFile"
                  :file-list="uploadFile.fileList"
                  :on-change="addFile"
                  multiple
                  :show-file-list="false"
                  :auto-upload="false"
                  :on-exceed="fileUploadExceed"
                >
                  <i class="el-icon-upload"></i>
                  <div class="el-upload__text">
                    将文件拖到此处，或
                    <em>点击上传</em>
                  </div>
                  <div class="el-upload__tip" slot="tip">只能上传pdf/图片文件,最多不超过5MB</div>
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" plain @click="uploadDialog.show = false">关 闭</el-button>
        <el-button type="primary" size="mini" @click="doUploadFile">保存</el-button>
      </span>
    </el-dialog>
    <!-- 附件查看dialog -->
    <el-dialog
      :title="viewFileDialog.title"
      :visible.sync="viewFileDialog.show"
      style="padding: 0"
      :width="viewFileDialog.width"
      :close-on-click-modal="false"
      @close="viewFileDialogClose"
      @opened="viewFileDialogOpened"
      v-el-drag-dialog
      v-dialogDrag
    >
      <img v-if="showImg" :src="filePath" height="800" alt="附件图片" ref="viewFileImgRef" />
      <!-- <iframe
        v-if="showImg"
        align="middle"
        class="prism-player"
        :src="filePath"
        width="100%"
        height="800"
      ></iframe>-->
      <div v-if="!showImg">
        <!-- <pdf
          v-for="i in pdfPage.total"
          :key="i"
          :page="i"
          :src="filePath"
          ref="pdf"
          :class="(i < pdfPage.total) ? 'pdfS' : ''"
        ></pdf>-->
        <iframe class="prism-player" :src="filePath" width="100%" height="800"></iframe>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" plain @click="viewFileDialog.show = false">关 闭</el-button>
      </span>
    </el-dialog>

    <!--驳回弹出框-->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" :close-on-click-modal="false">
      <span>请确定是否驳回</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="doBack" size="mini">确 定</el-button>
      </span>
    </el-dialog>
    <!--文件列表 -->
    <el-dialog title="合同附件" :visible.sync="dialogTableVisible" :close-on-click-modal="false">
      <el-table :data="gridData">
        <el-table-column type="index" width="60" align="center" label="序号"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="文件名称" prop="aname" width="200"></el-table-column>
        <!-- <el-table-column show-overflow-tooltip align="center" label="文件地址" prop="apath" width="500"></el-table-column> -->
        <el-table-column show-overflow-tooltip align="center" label="上传人" prop="acreate" width="200"></el-table-column>
        <el-table-column show-overflow-tooltip align="center" label="上传时间" prop="acreateTime"></el-table-column>
        <el-table-column prop="manage" label="操作" width="300">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="lookFile(scope.row)">预览</el-button>
            <el-button size="mini" type="primary" @click="down(scope.row)">下载</el-button>
            <el-button size="mini" type="primary" v-if="scope.row.acreate == storeName ? true : false" @click="deleteFile(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 终止合同弹框 -->
    <el-dialog
      width="30%"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      v-el-drag-dialog
      :title="annoucetDialogTitle"
      :visible.sync="annoucetDialog"
      v-if="annoucetDialog"
    >
      <el-form label-position="right" :model="annouceData" ref="annouceData" :rules="annouceDataRules" label-width="auto" size="mini">
        <el-row>
          <el-col :span="22">
            <el-form-item prop="weightEnd" label="终止重量：">
              <el-input v-model="annouceData.weightEnd" placeholder="请输入终止重量" clearable filterable :disabled="isDis"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 20px">
        <el-button size="mini" @click=";(annoucetDialog = false), (this.annouceData = [])">关闭</el-button>
        <el-button size="mini" type="primary" @click="terminationTrue">确认终止</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import scrollChange from '@/utils/onscroll.js'
import paginationMixin from '@/mixins/pagination'
import resizeMixin from '@/mixins/resize'
import isAtuth from '@/mixins/buttonAuth'
import Myprint from '@/plugins/print'
import store from '@/store'
import pdf from 'vue-pdf'
import buttonName from '@/components/buttonName/button-name.vue'
import dragTableHeader from '@/components/dragTableHeader'

import moment from 'moment'
import {
  exportContract,
  lineSign,
  queryService,
  phoneOrpeople,
  dropdownsh,
  downBillsFile,
  delFile,
  getFileList,
  updateback,
  findStats,
  upContractDocument,
  findContractModel2,
  queryBiddingInfoList,
  findefang,
  findjfang,
  findjfangType,
  effective,
  getNormListDropDownSer1,
  queryDemandLine,
  contractSugar,
  getSupplier,
  getShipper,
  contractBidding,
  getRefCodesByType,
  downloadContractHtmlModel,
  addContractModel,
  findContractModel,
  editContractModel,
  delContractModel,
  contractGenerateNo,
  findContractTemplateModel,
  downloadContractModel,
  selectSysCompanyByFltName,
  terminationContract,
} from '@/request/api'
export default {
  name: 'router.threedealManage',
  mixins: [paginationMixin, resizeMixin, isAtuth],
  data() {
    const weightEndValidate = (rule, value, callback) => {
      console.log(value)
      console.log(this.currentData)
      if (value) {
        if (parseFloat(value).toString() === 'NaN') {
          callback(new Error('请输入数字'))
          return
        }
        if (Number(value) > Number(this.currentData.cmtContractTotalTransport)) {
          callback(new Error('终止重量不能超过合同总重量'))
          return
        }
        callback()
      }
      callback(new Error('请输入终止重量'))
    }
    return {
      tableHeader: [
        {
          type: 'index',
          label: '序号',
          width: 60,
        },
        {
          type: 'selection',
          width: 55,
        },
        {
          label: '签订状态',
          prop: 'cmtContractState',
          width: 120,
          component: {
            props: ['row', 'data'],
            template: `<div>  <p v-if="row.row.cmtContractState=='0'">未签订</p>
                      <p v-if="row.row.cmtContractState=='2'">已生成订单计划</p>
                      <p v-if="row.row.cmtContractState=='3'">待确定</p>
                      <p v-if="row.row.cmtContractState=='4'">终止待确认</p>
                      <p v-if="row.row.cmtContractState=='5'">已终止</p>
                      <p v-if="row.row.cmtContractState=='6'">被驳回</p>
                      <p
                        v-if="row.row.cmtContractState!='0' && row.row.cmtContractState!='2'&& row.row.cmtContractState!='3'
                            && row.row.cmtContractState!='4' && row.row.cmtContractState!='5'&& row.row.cmtContractState!='6'"
                      >已签订</p></div>`,
          },
        },
        {
          label: '签订时间',
          prop: 'cmtSigningTime',
          width: 165,
        },
        {
          label: '合同编号',
          prop: 'cmtContractNo',
          width: 165,
        },
        {
          label: '合同名称',
          prop: 'cmtContractName',
          width: 150,
        },
        {
          label: '电子签章',
          prop: 'cmtLineIsSign',
          width: 110,
          component: {
            props: ['row', 'data'],
            template: `<div>  <el-checkbox
                        :value="row.row.cmtLineIsSign=='Y'?true:false"
                        :disabled="true"
                      ></el-checkbox>
            </div>`,
          },
        },
        {
          label: '合同类型',
          prop: 'cmtContractTypeName',
          width: 150,
        },
        {
          label: '托运人',
          prop: 'cmtPartyAName',
          width: 130,
        },
        {
          label: '承运人',
          prop: 'cmtPartyBName',
          width: 130,
        },
        {
          label: '托运人联系人',
          prop: 'cmtPartyAContacts',
        },
        {
          label: '托运人联系电话',
          prop: 'cmtPartyAPhone',
          width: 150,
        },
        {
          label: '承运人联系人',
          prop: 'cmtPartyBContacts',
          width: 150,
        },
        {
          label: '承运人联系电话',
          prop: 'cmtPartyBPhone',
          width: 150,
        },
        {
          label: '目的地收货人',
          prop: 'cmtConsigneeInformation',
          width: 180,
        },
        {
          label: '收货地点',
          prop: 'cmtPlaceReceipt',
          width: 180,
        },
        {
          label: '收货联系人',
          prop: 'cmtReceivingContact',
          width: 180,
        },
        {
          label: '收货人联系电话',
          prop: 'cmtReceivingPhone',
          width: 180,
        },
        {
          label: '装货地点',
          prop: 'cmtLoadingPlace',
          width: 180,
        },
        {
          label: '装货地点联系方式',
          prop: 'cmtLoadingContact',
          width: 180,
        },
        {
          label: '包装方式',
          prop: 'cmtPackingMethod',
          width: 130,
        },
        {
          label: '单件重量',
          prop: 'cmtSingleWeight',
          width: 130,
        },
        {
          label: '运输方式',
          prop: 'cmtShippingType',
          width: 130,
        },
        {
          label: '运输单价',
          prop: 'cmtTransportUnitPrice',
          width: 130,
        },
        {
          label: '运费合计',
          prop: 'cmtTotalFreight',
          width: 130,
        },
        {
          label: '承运起始日期',
          prop: 'cmtStartDateShipment',
          width: 130,
        },
        {
          label: '最迟装货日期',
          prop: 'cmtLatestLoadingDate',
          width: 130,
        },
        {
          label: '公司名称',
          prop: 'cmtCorporateName',
          width: 120,
        },
        {
          label: '开户行',
          prop: 'cmtOpeningBank',
          width: 120,
        },
        {
          label: '账号',
          prop: 'cmtAccount',
          width: 120,
        },
      ],
      usrType: '',
      fltCode: '',
      eContractSee: false,
      goodarr: [], //货物数组
      storeName: '',
      multipleSelection: [], //多选数据数组
      //签订状态
      contractStates: [
        {
          code: '0',
          name: '未签订',
        },
        {
          code: '1',
          name: '已签订',
        },
        {
          code: '2',
          name: '已生成订单计划',
        },
        {
          code: '3',
          name: '待确定',
        },
        {
          code: '4',
          name: '终止待确定',
        },
        {
          code: '5',
          name: '已终止',
        },
        {
          code: '6',
          name: '被驳回',
        },
      ],
      mddslist: [], //目的地收货方
      shlxrlist: [], //收获联系人
      lxrphonelist: [], //联系人电话
      annoucetDialog: false, //合同终止 Dialog
      annouceData: {}, //合同终止数据
      annoucetDialogTitle: '', //title
      isDis: false, //是否可编辑

      priceseeA: true,
      dialogTableVisible: false,
      dialogVisible: false,
      disabled: false,
      viewFileDialog: {
        title: '',
        show: false,
        width: 0.5,
      },
      gridData: [],
      pdfPage: {
        index: 0,
        total: 0,
      },
      showImg: true,
      uploadFileRules: {
        name: [{ required: true, message: '文件名称不能为空', trigger: 'change' }],
      },
      annouceDataRules: {
        weightEnd: [{ validator: weightEndValidate, trigger: 'blur' }],
      },
      uploadFile: {
        name: '',
        fileList: [],
      },
      uploadDialog: {
        title: '',
        show: false,
      },
      filePath: '',
      fltType: '',
      tranDialogInfoDialogVisible: false,
      tranDialogInfoList: [],
      contractSugarTemporary: {},
      quotaDialog: {}, //供应商
      biddingTemporary: {},
      contractSugarList: [],
      biddingList: [],
      biddingHeight: -1,
      dailyOutputs: [],
      quotaDialogList: [], //供应商
      jfdropdown: [], //甲方下拉框
      jftype: '',
      efdropdown: [], //乙方下拉框
      RefTypeDialogVisible: false, //选择标书弹出框
      supplier: false, //控制页面查询条件 供应商页面区分
      expire: false, //是不是预警页面
      feeValue: '', //标签名称
      cmtPartyAName: '', //托运方名称
      cmtPartyBName: '', //承运方
      isShow: false,
      queryParam: {
        bidCode: '', // 标的编号
        bidName: '', //标的名称
      },
      querydemandParam: {
        demandCode: '',
      },
      form: {
        //搜索条件
        cmtContractState: '',
        cmtContractNo: '',
        cmtContractType: '',
        start: '',
        end: '',
        cmtPartyAName: '',
        cmtPartyBName: '',
        cmtShippingType: '', // 运输类型
      },
      sumcddQuantity: 0,
      tableDataheight: '-',
      templateObjec: {
        height: '',
      },
      tableHeight: 300,
      cmtContractType: [],
      img: '',
      html: '',
      downloadWidth: '40%',
      downloadType: 'doc',
      downloadOpenDialog: false, //附件下载 控制
      rowDataArray: {}, //线路信息 点击列获取
      tableDataArray: [], //线路信息 列表
      templateList: [], //模板列表
      modeList: [],
      dialogDownloadFormRule: {
        templateTvalue: [{ required: true, message: '模板不能为空', trigger: 'blur' }],
      },
      dialogDownloadForm: {
        templateTvalue: '',
      },
      templateTvalue: '',
      typeHeight: -1,
      detlHeight: -1,
      tableData: [], //合同主列表
      mainBotTableData: [], //子表
      currentData: {}, //主列表单击时暂存数据
      // 对话框名称
      name: '',
      openDialog: false,
      dialogForm: {
        cmtContractMainno: '',
        cmtIsthrid: 'Y',
        cmtContractTotalTransport: 0,
        bidId: '',
        cmtContractNo: '',
        cmtContractType: '',
        cmtContractName: '',
        cmtPartyA: '',
        cmtPartyAContacts: '',
        cmtPartyAPhone: '',
        cmtPartyB: '',
        cmtPartyBContacts: '',
        cmtPartyBPhone: '',
        cmtConsigneeInformation: '',
        cmtPlaceReceipt: '',
        cmtReceivingContact: '',
        cmtReceivingPhone: '',
        cmtLoadingPlace: '',
        cmtLoadingContact: '',
        cmtGoodsName: '',
        cmtPackingMethod: '',
        cmtSingleWeight: '',
        cmtShippingType: '',
        cmtTransportUnitPrice: '',
        cmtTotalFreight: '',
        cmtStartDateShipment: '',
        cmtLatestLoadingDate: '',
        cmtCorporateName: '',
        cmtOpeningBank: '',
        cmtAccount: '',
      },
      dialogRule: {
        cmtContractNo: [{ required: true, message: '合同编号不能为空', trigger: 'blur' }],
        cmtContractType: [{ required: true, message: '合同类型不能为空', trigger: 'blur' }],
        cmtStartDateShipment: [{ required: true, message: '承运起始日期不能为空', trigger: 'blur' }],
        cmtLatestLoadingDate: [{ required: true, message: '最迟装货日期不能为空', trigger: 'blur' }],
        cmtPartyA: [{ required: true, message: '托运方不能为空', trigger: 'blur' }],
        cmtPartyB: [{ required: true, message: '承运方不能为空', trigger: 'blur' }],
        bidId: [{ required: true, validator: this.chckbidId, trigger: 'blur' }],
        cmtContractName: [{ required: true, message: '合同名称不能为空', trigger: 'blur' }],
        cmtConsigneeInformation: [{ required: true, message: '目的地收货方不能为空', trigger: 'blur' }],
        cmtPlaceReceipt: [{ required: true, message: '收货地点不能为空', trigger: 'blur' }],
        cmtReceivingContact: [{ required: true, message: '收货联系人不能为空', trigger: 'blur' }],
        cmtReceivingPhone: [{ required: true, message: '收货人联系电话不能为空', trigger: 'blur' }],
        cmtPartyAContacts: [{ required: true, message: '托运方联系人不能为空', trigger: 'blur' }],
        cmtPartyAPhone: [{ required: true, message: '托运方联系电话不能为空', trigger: 'blur' }],
        cmtLoadingPlace: [{ required: true, message: '装货地点不能为空', trigger: 'blur' }],
        // cmtLoadingContact: [
        //   {
        //     required: true,
        //     message: '装货地点联系方式不能为空',
        //     trigger: 'blur'
        //   }
        // ],
        cmtPartyBContacts: [{ required: true, message: '承运方联系人不能为空', trigger: 'blur' }],
        cmtPartyBPhone: [{ required: true, message: '承运方联系电话不能为空', trigger: 'blur' }],
      },
      edit: false, // 编辑模式
      see: false, //查看模式
      pricesee: false, //查看单价
      qdsee: false, //查看签订
      filesee: false, //查看附件
      shippingType: [], // 运输类型
    }
  },
  components: {
    buttonName,
    pdf,
    dragTableHeader,
  },
  created() {
    this.resize = () => {
      this.typeHeight = this.$refs.topType.offsetHeight - 80
      this.detlHeight = this.$refs.bottomCode.offsetHeight - 130
      this.biddingHeight = this.$refs.bottomCode.offsetHeight - 80
    }
    this.storeName = store.state.user.USR_CODE_DX_H
  },
  mounted() {
    const contractNo = this.$route.params.contractNo
    if (contractNo) {
      this.form.cmtContractNo = contractNo
    }

    dropdownsh({ param: 'cmt_consignee_information' }).then(res => {
      this.mddslist = res.data
    })
    dropdownsh({ param: 'cmt_receiving_contact' }).then(res => {
      this.shlxrlist = res.data
    })
    dropdownsh({ param: 'cmt_receiving_phone' }).then(res => {
      this.lxrphonelist = res.data
    })
    let demandWrapper = document.querySelector('.demand .el-table__body-wrapper') // 新增滚动条监听事件
    scrollChange(demandWrapper)

    // this.getdatatime()
    getRefCodesByType('包装方式').then(ref => {
      this.modeList = ref.data
    })
    getRefCodesByType('合同类型').then(ref => {
      this.cmtContractType = ref.data
    })

    /**
     * 货物规格
     *
     */
    getNormListDropDownSer1().then(res => {
      if (res.success === '1') {
        this.dailyOutputs = res.data
      }
    })
    findjfang().then(res => {
      if (res.success == '1') {
        this.jfdropdown = res.data
      }
    })
    findefang().then(res => {
      if (res.success == '1') {
        this.efdropdown = res.data
      }
    })
    findjfangType({
      fltId: this.$store.state.user.FLT_UUID_DX_H,
      dptId: this.$store.state.user.DPTID_DX_H,
    }).then(res => {
      if (res.data != null) {
        this.usrType = res.data.type
        this.fltCode = this.usrType + this.$store.state.user.DPTID_DX_H
      } else {
        this.usrType = 'PT'
        this.fltCode = this.usrType + Math.abs(this.$store.state.user.FLT_UUID_DX_H)
      }
    })
    this.getShippingTypeList()
    this.refreshList()
  },
  methods: {
    //后端导出
    // outExcel() {
    //   exportContract({ list: this.multipleSelection }).then(res => {
    //     const fileName = decodeURI(res.headers['filename'])
    //     const reader = new FileReader()
    //     reader.readAsDataURL(new Blob([res.data]))
    //     reader.onload = e => {
    //       let a = document.createElement('a')
    //       a.download = fileName
    //       a.href = e.target.result
    //       document.body.appendChild(a)
    //       a.click()
    //       document.body.removeChild(a)
    //     }
    //     window.parent._$store.dispatch('app/loading_status', false)
    //   })
    // },
    //vue Export2Excel 导出
    outExcel() {
      if (this.multipleSelection.length === 0) {
        this.$message.error('请选择要导出的合同')
        return
      }
      var filename = '合同报表' + moment(new Date()).format('YYYYMMDDHHmmss')
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = [
          '序号',
          '签订状态',
          '签订时间',
          '合同编号',
          '合同名称',
          '电子签章',
          '合同类型',
          '托运人',
          '承运人',
          '托运人联系人',
          '托运人联系电话',
          '承运人联系人',
          '承运人联系电话',
          '目的地收货人',
          '收货地点',
          '收货联系人',
          '收货人联系电话',
          '装货地点',
          '装货地点联系方式',
          '包装方式',
          '单件重量',
          '运输方式',
          '运输单价',
          '运费合计',
          '承运起始日期',
          '最迟装货日期',
          '公司名称',
          '开户行',
          '账号',
        ]
        const filterVal = [
          'index',
          'cmtContractState',
          'cmtSigningTime',
          'cmtContractNo',
          'cmtContractName',
          'cmtLineIsSign',
          'cmtContractTypeName',
          'cmtPartyAName',
          'cmtPartyBName',
          'cmtPartyAContacts',
          'cmtPartyAPhone',
          'cmtPartyBContacts',
          'cmtPartyBPhone',
          'cmtConsigneeInformation',
          'cmtPlaceReceipt',
          'cmtReceivingContact',
          'cmtReceivingPhone',
          'cmtLoadingPlace',
          'cmtLoadingContact',
          'cmtPackingMethodName',
          'cmtSingleWeightName',
          'cmtShippingType',
          'cmtTransportUnitPrice',
          'cmtTotalFreight',
          'cmtStartDateShipment',
          'cmtLatestLoadingDate',
          'cmtCorporateName',
          'cmtOpeningBank',
          'cmtAccount',
        ]
        const list = this.multipleSelection
        const data = this.formatJson(filterVal, list)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: filename,
          autoWidth: true,
        })
        this.downloadLoading = false
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v, index) =>
        filterVal.map(j => {
          if (j === 'cmtLineIsSign') {
            if (v[j] === 'Y') {
              return '是'
            } else {
              return '否'
            }
          }
          if (j === 'cmtContractState') {
            if (v[j] === '0') {
              return '未签订'
            } else if (v[j] === '2') {
              return '已生成订单计划'
            } else if (v[j] === '3') {
              return '待确定'
            } else if (v[j] === '4') {
              return '终止待确认'
            } else if (v[j] === '5') {
              return '已终止'
            } else if (v[j] === '6') {
              return '被驳回'
            } else {
              return '已签订'
            }
          }
          if (j === 'index') {
            return index + 1
          }
          return v[j]
        })
      )
    },
    viewContract() {
      window.open(this.currentData.cmtLineViewUrl, '_blank')
    },
    downContract() {
      window.location.href = this.currentData.cmtLineDownUrl
    },
    selectGys() {
      if (this.dialogForm.cmtPartyB == -1) {
        // //设置承运方联系人
        this.dialogForm.cmtPartyBContacts = '李翠芳'
        // //设置承运方联系人电话
        this.dialogForm.cmtPartyBPhone = '18260866919'
        // //设置公司名称
        this.dialogForm.cmtCorporateName = '广西泛糖科技有限公司'
        // //设置开户行
        this.dialogForm.cmtOpeningBank = '中国建设银行（南宁新城支行）'
        // //设置账号
        this.dialogForm.cmtAccount = '45050160425500000619'
      } else {
        queryService({ companyId: this.dialogForm.cmtPartyB }).then(res => {
          // //设置承运方联系人
          this.dialogForm.cmtPartyBContacts = String(res.data.fltContact)
          // //设置承运方联系人电话
          this.dialogForm.cmtPartyBPhone = String(res.data.fltContactPhone)
          // //设置公司名称
          this.dialogForm.cmtCorporateName = String(res.data.fltName)
          // //设置开户行
          this.dialogForm.cmtOpeningBank = String(res.data.fltBank)
          // //设置账号
          this.dialogForm.cmtAccount = String(res.data.fltAccount)
        })
      }
    },
    getRowkeys(row) {
      return row.index
    },
    //获取多条数据
    handleSelectionChange(val) {
      this.multipleSelection = val
      console.log(this.multipleSelection)
    },
    //绑定收货方信息
    bangding() {
      this.dialogForm.cmtReceivingContact = ''
      this.dialogForm.cmtReceivingPhone = ''
      let code = this.dialogForm.cmtConsigneeInformation

      if (code === '' || code === null) {
        dropdownsh({ param: 'cmt_receiving_contact' }).then(res => {
          this.shlxrlist = res.data
        })
        dropdownsh({ param: 'cmt_receiving_phone' }).then(res => {
          this.lxrphonelist = res.data
        })
      } else {
        phoneOrpeople({ param: 'cmt_receiving_contact', place: code }).then(res => {
          this.shlxrlist = res.data
          phoneOrpeople({ param: 'cmt_receiving_phone', place: code }).then(res => {
            this.lxrphonelist = res.data
            if (this.shlxrlist.length !== 0) {
              this.dialogForm.cmtReceivingContact = String(this.shlxrlist[0].value)
            }
            if (this.lxrphonelist.length !== 0) {
              this.dialogForm.cmtReceivingPhone = String(this.lxrphonelist[0].value)
            }
          })
        })
        // if (!isNaN(Number(code)))
        // try {
        //   console.log(code)
        //   for (let index = 0; index < this.shlxrlist.length; index++) {
        //     if (this.shlxrlist[index].code == code) {
        //       this.dialogForm.cmtReceivingContact = String(code)
        //     }
        //   }
        //   for (let i = 0; i < this.lxrphonelist.length; i++) {
        //     if (this.lxrphonelist[i].code == code) {
        //       this.dialogForm.cmtReceivingPhone = String(code)
        //     }
        //   }
        // } catch (error) {
        //   console.log(error)
        // }
      }
    },
    //平台发起合同终止 4--终止待确认  5--已终止
    termination() {
      if (Object.keys(this.currentData).length === 0) {
        this.$message.error('请选择需要终止的合同信息！')
        return
      }
      if (
        this.currentData.cmtContractState == '0' ||
        this.currentData.cmtContractState == '3' ||
        this.currentData.cmtContractState == '4' ||
        this.currentData.cmtContractState == '5'
      ) {
        this.$message.error('请选择已签订的合同信息！')
        return
      }
      this.annoucetDialogTitle = '终止合同'
      this.isDis = false
      this.annoucetDialog = true
    },

    //确认终止合同
    terminationTrue() {
      this.$refs['annouceData'].validate(valid => {
        if (!valid) {
          // this.$message.error('必输项不能为空！')
          return false
        }
        terminationContract({
          weightEnd: this.annouceData.weightEnd,
          cmtId: this.currentData.cmtId,
          cmtContractState: this.isDis ? '5' : '4',
        }).then(res => {
          if (res.success == '1') {
            this.$message.success('操作成功！')
            this.refreshList()
            this.annoucetDialog = false
            this.annouceData = []
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },

    //糖厂货主终止确认
    confirmEnd() {
      if (Object.keys(this.currentData).length === 0) {
        this.$message.error('请选择需要确认终止的合同信息！')
        return
      }
      if (this.currentData.cmtContractState != '4') {
        this.$message.error('请选择终止待确认的合同信息！')
        return
      }
      this.annoucetDialogTitle = '确认合同终止'
      this.isDis = true
      this.annouceData.weightEnd = this.currentData.cmtTerminationWeight
      this.annoucetDialog = true
    },

    //调取父组件方法
    addservice() {
      if (Object.keys(this.currentData).length === 0) {
        this.$message.error('请选择需要新增的服务合同托运信息！')
        return
      }
      if (this.currentData.cmtContractState !== '0') {
        this.$message.error('请选择未签订的托运信息！')
        return
      }
      if (this.currentData.cmtIsthrid !== 'N') {
        this.$message.error('当前托运信息存在第三方')
        return
      }
      if (this.currentData.cmtIsthrid == 'N') {
        // console.log(this.currentData)
        this.currentData.cmtContractType = 'service'
        this.currentData.cmtContractTypeName = '服务合同'
        this.currentData.cmtPartyA = '-1'
        this.currentData.cmtPartyAName = '泛糖科技'
        this.currentData.consignmentDetailedList = this.currentData.consignmentDetailedVOs
        contractGenerateNo({
          cmtPartyA: this.currentData.cmtPartyA,
          cmtIsthrid: this.currentData.cmtIsthrid,
        }).then(res => {
          this.currentData.cmtContractNo = res.data
          addContractModel(this.currentData).then(res => {
            if (res.success === '1') {
              this.$message({
                type: 'success',
                message: '新增合同成功！',
              })
              this.refreshList()
            }
          })
        })
      }
    },
    clickEventDom(item) {
      if (item.mdlCode === 'addContract') {
        this.addCar()
      } else if (item.mdlCode === 'editContract') {
        this.editCar()
      } else if (item.mdlCode === 'delContract') {
        this.delCar()
      } else if (item.mdlCode === 'downloadContract') {
        this.downloadDialog('doc')
      } else if (item.mdlCode === 'printContract') {
        this.downloadDialog('html')
      } else if (item.mdlCode === 'sign') {
        this.effective2()
      } else if (item.mdlCode === 'back') {
        this.goback()
      } else if (item.mdlCode === 'service') {
        this.addservice()
      } else if (item.mdlCode === 'termination') {
        this.termination()
      } else if (item.mdlCode === 'confirmEnd') {
        this.confirmEnd()
      } else if (item.mdlCode === 'outExcel') {
        this.outExcel()
      }
    },
    searchDemand() {
      if ('number' !== typeof this.biddingTemporary.bidId) {
        this.$alert('请选择想要关联的标', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      console.log(this.querydemandParam.demandCode)
      contractSugar(this.biddingTemporary.bidId, this.querydemandParam.demandCode).then(ref => {
        this.contractSugarList = ref.data
      })
      this.contractSugarTemporary = {}
      this.quotaDialogList = []
    },
    searchType() {
      contractBidding({
        bidCode: this.queryParam.bidCode,
        bidName: this.queryParam.bidName,
      }).then(res => {
        this.biddingList = res.data
      })
      this.biddingTemporary = {}
      this.contractSugarList = []
      this.contractSugarTemporary = {}
      this.quotaDialogList = []
    },
    down(val) {
      downBillsFile({ id: val.aid }).then(res => {
        const fileName = decodeURI(res.headers['filename'])
        if (res.headers['fileexists']) {
          this.$message.error('文件不存在')
          return
        }
        const reader = new FileReader()
        reader.readAsDataURL(new Blob([res.data]))
        reader.onload = e => {
          let a = document.createElement('a')
          a.download = fileName
          a.href = e.target.result
          document.body.appendChild(a)
          a.click()
          document.body.removeChild(a)
        }
        window.parent._$store.dispatch('app/loading_status', false)
        this.$message.success('请等待浏览器响应')
      })
    },
    lookFile(val) {
      // path 没有被组件转换
      this.filePath = val.apath

      if (typeof this.filePath == 'string') {
        try {
          if (process.env.NODE_ENV != 'production' && !this.filePath.startsWith('/proxy')) {
            this.filePath = '/proxy' + this.filePath
          }

          this.showImg = !this.filePath.endsWith('.pdf')

          // if (this.filePath.endsWith('.pdf')) {
          // this.filePath = pdf.createLoadingTask(this.filePath)
          // this.filePath.promise.then(pdf => {
          // this.pdfPage.total = pdf.numPages
          // })
          // }
          this.viewFileDialog.title = '附件'
          this.viewFileDialog.show = true
          return
        } catch (error) {
          console.log(error)
        }
      }
      this.viewFileDialog.title = '附件'
      this.viewFileDialog.show = true
    },
    deleteFile(val) {
      console.log(val)
      if (this.currentData.cmtContractState !== '0' && this.currentData.cmtContractState !== '6' && this.currentData.cmtContractState !== '5') {
        this.$message.error('合同已签订无法删除')
        return
      }
      delFile({ aId: val.aid }).then(res => {
        if (res.success == '1') {
          this.$message.success('删除成功')
          getFileList({ pubId: this.currentData.cmtId, module: 'HT' }).then(res => {
            this.gridData = res.data
            console.log(this.gridData)
          })
        }
      })
    },
    getdatatime() {
      //默认显示一周内的
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      this.form.start = start
      this.form.end = new Date()
    },
    viewFile() {
      this.dialogTableVisible = true
      try {
        getFileList({ pubId: this.currentData.cmtId, module: 'HT' }).then(res => {
          this.gridData = res.data
          console.log(this.gridData)
        })
      } catch (error) {
        console.log(error)
      }
    },
    removeFile() {
      this.uploadFile.name = ''
      this.uploadFile.fileList = []
    },
    addFile(val) {
      this.uploadFile.fileList.push(val.raw)
      this.uploadFile.name = val.name
    },
    fileUploadExceed(val) {
      this.uploadFile.name = val[0].name
      this.uploadFile.fileList = val
    },
    uploadDialogClose() {
      this.$refs.uploadFileFrom.resetFields()
      this.removeFile()
    },
    viewFileDialogClose() {
      // 重置宽度
      this.viewFileDialog.width = 0.5
    },
    viewFileDialogOpened() {
      if (typeof this.filePath == 'string' && !this.filePath.endsWith('.pdf')) {
        this.viewFileDialog.width = this.$refs.viewFileImgRef.width + 40 + 'px'
      }
    },
    doUploadFile() {
      this.$refs.uploadFileFrom.validate(v => {
        if (v) {
          if (this.uploadFile.fileList.length == 0) {
            this.$message.error('请至少选择一个文件')
            return
          }
          let filecount = 0
          if (this.gridData.length !== 0) {
            for (let index = 0; index < this.gridData.length; index++) {
              if (this.gridData[index].acreate === store.state.user.USR_CODE_DX_H) {
                filecount++
              }
            }
          }
          if (filecount == 1) {
            this.$message.error('已有合同，请勿多次上传')
            return
          }
          try {
            let data = new FormData()
            data.append('file', this.uploadFile.fileList[0])
            data.append('type', 'Contract')

            upContractDocument({
              id: this.currentData.cmtId,
              file: data,
            }).then(res => {
              getFileList({ pubId: this.currentData.cmtId, module: 'HT' }).then(res => {
                this.gridData = res.data
                console.log(this.gridData)
              })
              this.$message.success('上传成功')
              this.uploadDialog.show = false
            })
          } catch (error) {
            console.log(error)
          }
        }
      })
    },
    openUploadDialog() {
      this.uploadDialog.title = '附件上传'
      this.uploadDialog.show = true
    },
    savebidding() {
      let biddingTemporary = this.biddingTemporary || {}
      let contractSugarTemporary = this.contractSugarTemporary || {}
      let quotaDialog = this.quotaDialog || {}
      let tranDialogInfoList = this.tranDialogInfoList || []
      let mes = null
      if (contractSugarTemporary.sugarId == null) {
        mes = '请选择想要关联的需求'
      }
      if (mes != null) {
        this.$alert(mes, '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      if (quotaDialog.fltId == null) {
        mes = '请选择想要关联的供应商'
      }
      if (mes != null) {
        this.$alert(mes, '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      try {
        // 设置运输方式
        this.dialogForm.cmtShippingType = contractSugarTemporary.transportMode
        // //设置单件重量公斤
        this.dialogForm.cmtSingleWeight = contractSugarTemporary.dailyOutputCode
        // //设置标签名称
        this.feeValue = biddingTemporary.bidName
        // //设置标签id
        this.dialogForm.bidId = biddingTemporary.bidId
        // //设置托运方
        this.dialogForm.cmtPartyA = String(contractSugarTemporary.consignorId)
        this.cmtPartyAName = contractSugarTemporary.consignorName
        // //设置托运方联系人
        this.dialogForm.cmtPartyAContacts = contractSugarTemporary.dptCorporation
        // //设置托运方联系人电话
        if (contractSugarTemporary.dptPhone != null) {
          this.dialogForm.cmtPartyAPhone = String(contractSugarTemporary.dptPhone)
        } else {
          this.dialogForm.cmtPartyAPhone = ''
        }
        // //设置承运方
        this.dialogForm.cmtPartyB = String(quotaDialog.fltId)
        this.cmtPartyBName = quotaDialog.usrName
        // //设置承运方联系人
        this.dialogForm.cmtPartyBContacts = String(quotaDialog.fltLinkperson)
        // //设置承运方联系人电话
        this.dialogForm.cmtPartyBPhone = String(quotaDialog.fltLinkphone)
        // //设置公司名称
        this.dialogForm.cmtCorporateName = String(quotaDialog.usrName)
        // //设置开户行
        this.dialogForm.cmtOpeningBank = String(quotaDialog.fltBank)
        // //设置账号
        this.dialogForm.cmtAccount = String(quotaDialog.fltAccount)
        //

        let jfang = []
        for (let i = 0; i < this.jfdropdown.length; i++) {
          if (this.jfdropdown[i].code == this.dialogForm.cmtPartyA) {
            jfang.push(this.jfdropdown[i])
          }
        }

        for (let i = 0; i < this.jfdropdown.length; i++) {
          if (this.jfdropdown[i].type == 'PT') {
            jfang.push(this.jfdropdown[i])
          }
        }
        this.jfdropdown = jfang
        let efang = []
        for (let i = 0; i < this.efdropdown.length; i++) {
          if (this.efdropdown[i].code == this.dialogForm.cmtPartyB) {
            efang.push(this.efdropdown[i])
          }
        }

        for (let i = 0; i < this.efdropdown.length; i++) {
          if (this.efdropdown[i].type == 'PT') {
            efang.push(this.efdropdown[i])
          }
        }
        this.efdropdown = efang
        //设置运输总量
        this.dialogForm.cmtContractTotalTransport = quotaDialog.bqTransportQuantity
        //设置运输单价
        this.dialogForm.cmtTransportUnitPrice = quotaDialog.biddingPrice
        //设置运输总价格
        this.dialogForm.cmtTotalFreight = (this.dialogForm.cmtTransportUnitPrice * this.dialogForm.cmtContractTotalTransport).toFixed(2)
        //设置装货地
        this.dialogForm.cmtLoadingPlace = tranDialogInfoList[0].site || ''
        //设置收货地
        this.dialogForm.cmtPlaceReceipt = tranDialogInfoList[0].destination || ''
        //设置品牌
        // this.tableDataArray.forEach(o => {
        //   o.cddBrand = o.cddBrand || contractSugarTemporary.brand
        // })
        this.tableDataArray.forEach(o => {
          ;(o.cddBrand = o.cddBrand || contractSugarTemporary.brand), (o.cddQuantity = o.cddQuantity || quotaDialog.bqTransportQuantity)
        })
        //绑定需求id
        this.dialogForm.sugarId = contractSugarTemporary.sugarId
        console.log(quotaDialog)
        this.dialogForm.bqId = quotaDialog.bqId
        //关闭窗口
        console.log(this.dialogForm.bqId)
        this.RefTypeDialogVisible = false
        //刷新唯一编号
        this.generateNo()
        this.quotaDialogList = []
        this.quotaDialog = {}
      } catch (error) {
        console.log(error)
      }
    },
    // dialog 查看线路详细信息
    showTransportMethod(val) {
      queryDemandLine({
        sugarId: val.sugarId,
      }).then(res => {
        if (res.success == 1) {
          this.tranDialogInfoList = res.data
        }
      })
    },
    showGYSinfo(val) {
      queryBiddingInfoList({
        bidId: val.bqBidId,
        sugarId: val.sugarId,
        biddingEnd: 'Y', //查询前三名推荐结果
        reviewStatus: 'Y', //评审状态
        quotaStatus: 'Y', //配额状态
      }).then(res => {
        if (res.success == 1) {
          this.quotaDialogList = res.data
        }
      })
    },
    contractSugarClick(row) {
      this.contractSugarTemporary = row
      this.quotaDialog = {}
      this.showTransportMethod(row)
      this.showGYSinfo(row)
    },
    quotaDialogListClick(row) {
      this.quotaDialog = row
    },
    biddingClick(row) {
      this.biddingTemporary = row
      this.contractSugarTemporary = {}
      this.quotaDialogList = []
      contractSugar(row.bidId).then(ref => {
        this.contractSugarList = ref.data
      })
    },
    handleTypeDialogClose() {
      this.RefTypeDialogVisible = false
      this.tranDialogInfoDialogVisible = false
    },
    calculationTotalFreight() {
      let val = parseFloat(this.dialogForm.cmtTransportUnitPrice || 0)
      this.dialogForm.cmtTotalFreight = this.dialogForm.cmtContractTotalTransport * val
    },
    chckbidId(rule, value, callback) {
      let val = this.dialogForm.bidId || null
      if (val == null) {
        return callback(new Error('标书不能为空'))
      }
      callback()
    },
    chckcddQuantity(rule, value, callback) {
      let val = value || null
      if (val == null) {
        return callback(new Error('数量不能为空'))
      } else {
        var v = 0
        this.tableDataArray.forEach(o => {
          v = parseFloat(o.cddQuantity) + v
        })
        if (!(this.dialogForm.cmtContractTotalTransport >= v)) {
          return callback(new Error('数量大于运输总量'))
        }
      }
      callback()
    },
    //标书数据
    BiddingList() {
      this.cmtPartyBName = ''
      this.cmtPartyAName = ''
      this.biddingTemporary = {}
      this.contractSugarTemporary = {}
      this.contractSugarList = []
      this.tranDialogInfoList = []
      contractBidding({}).then(res => {
        this.biddingList = res.data
      })
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (!this.expire) {
        return ''
      }
      if (column.label == '最迟装货日期' && new Date(row.cmtLatestLoadingDate).getTime() < new Date().getTime()) {
        return 'background: red'
      } else {
        return ''
      }
    },
    dateFormat(fmt, date) {
      let ret
      const opt = {
        'Y+': date.getFullYear().toString(), // 年
        'm+': (date.getMonth() + 1).toString(), // 月
        'd+': date.getDate().toString(), // 日
        'H+': date.getHours().toString(), // 时
        'M+': date.getMinutes().toString(), // 分
        'S+': date.getSeconds().toString(), // 秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
      }
      for (let k in opt) {
        ret = new RegExp('(' + k + ')').exec(fmt)
        if (ret) {
          fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'))
        }
      }
      return fmt
    },
    cmtStartDateShipmentChange() {
      if (this.dialogForm.cmtLatestLoadingDate != null && this.dialogForm.cmtLatestLoadingDate != '') {
        let cmtStartDateShipment = new Date(this.dialogForm.cmtStartDateShipment)
        if (cmtStartDateShipment.getTime() > new Date(this.dialogForm.cmtLatestLoadingDate).getTime()) {
          cmtStartDateShipment = cmtStartDateShipment.setDate(cmtStartDateShipment.getDate() + 1)
          this.dialogForm.cmtLatestLoadingDate = this.dateFormat('YYYY-mm-dd', new Date(cmtStartDateShipment))
        }
      }
    },
    getCmtContractStateName(v) {
      if (v.cmtContractState != '0') {
        return '已签订'
      }
      return '未签订'
    },
    printHtml() {
      Myprint.print(this.$refs.html_template)
    },
    disabledDate(time) {
      return time.getTime() < new Date(this.dialogForm.cmtStartDateShipment).getTime() - 8.64e7
    },
    generateNo() {
      if (this.dialogForm.cmtPartyA == null || this.dialogForm.cmtPartyA == '') {
        return
      }
      if (this.dialogForm.cmtPartyB == null || this.dialogForm.cmtPartyB == '') {
        return
      }

      // contractGenerateNo({
      //   cmtPartyA: this.cmtPartyAName,
      //   cmtPartyB: this.cmtPartyBName,
      //   cmtContractNo: this.dialogForm.cmtContractNo
      // }).then(res => {
      //   this.dialogForm.cmtContractNo = res.data
      // })
      contractGenerateNo({
        cmtPartyA: this.dialogForm.cmtPartyA,
        cmtIsthrid: this.dialogForm.cmtIsthrid,
      }).then(res => {
        this.dialogForm.cmtContractNo = res.data
      })
    },
    getList(currentPage, pageSize, fcTotal) {
      this.currentData = {}
      this.mainBotTableData = []
      let cmtPartyB = ''
      if (this.supplier) {
        cmtPartyB = store.state.user.FLT_UUID_DX_H
      }
      findjfangType({
        fltId: store.state.user.FLT_UUID_DX_H,
        dptId: store.state.user.DPTID_DX_H,
      }).then(res => {
        if (res.data != null) {
          this.jftype = res.data.type

          if (this.jftype == 'HZ' || this.jftype == 'TC') {
            findContractModel2({
              cmtPartyA: store.state.user.DPTID_DX_H,
              cmtPartyB,
              start: this.form.start,
              end: this.form.end,
              cmtContractState: this.form.cmtContractState,
              cmtPartyAName: this.form.cmtPartyAName,
              cmtPartyBName: this.form.cmtPartyBName,
              cmtContractType: this.form.cmtContractType,
              cmtContractNo: this.form.cmtContractNo,
              currentPage,
              pageSize,
              cmtShippingType: this.form.cmtShippingType,
            }).then(res => {
              this.tableData = res.data
              fcTotal(res.total)
            })
          } else {
            findContractModel2({
              cmtPartyB,
              cmtPartyA: store.state.user.DPTID_DX_H,
              start: this.form.start,
              end: this.form.end,
              cmtContractState: this.form.cmtContractState,
              cmtPartyAName: this.form.cmtPartyAName,
              cmtPartyBName: this.form.cmtPartyBName,
              cmtContractType: this.form.cmtContractType,
              cmtContractNo: this.form.cmtContractNo,
              currentPage,
              pageSize,
              cmtShippingType: this.form.cmtShippingType,
            }).then(res => {
              this.tableData = res.data
              fcTotal(res.total)
            })
          }
        } else {
          findContractModel2({
            cmtPartyA: store.state.user.DPTID_DX_H,
            cmtPartyB,
            start: this.form.start,
            end: this.form.end,
            cmtContractState: this.form.cmtContractState,
            cmtPartyAName: this.form.cmtPartyAName,
            cmtPartyBName: this.form.cmtPartyBName,
            cmtContractType: this.form.cmtContractType,
            cmtContractNo: this.form.cmtContractNo,
            currentPage,
            pageSize,
            cmtShippingType: this.form.cmtShippingType,
          }).then(res => {
            this.tableData = res.data
            fcTotal(res.total)
          })
        }
      })
    },
    numberOnly(data) {
      if (data == null) {
        return null
      }
      let val = data.toString().replace(/(^\s*)|(\s*$)/g, '')
      if (!val) {
        return val
      }
      val = val.replace(/[^\d.]/g, '')
      // 保证第一位只能是数字，不能是点
      val = val.replace(/^\./g, '')
      // 小数只能出现1位
      val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      // 小数点后面保留2位
      val = val.replace(/^(\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3')
      return val
    },
    doBack() {
      updateback(this.currentData.cmtId).then(res => {
        if (res.success == '1') {
          this.dialogVisible = false
          this.$message.success('驳回成功!')
          this.refreshList()
        }
      })
    },
    goback() {
      if (Object.keys(this.currentData).length === 0) {
        this.$message.error('请选择需要驳回的托运信息！')
        return
      }
      if (this.currentData.cmtContractState === '2') {
        this.$message.error('已经生成订单计划无法驳回！')
        return
      }
      if (this.currentData.cmtContractState != '3' && this.currentData.cmtContractState != '1') {
        this.$message.error('请选择待确定或已签订的托运信息！')
        return
      }
      this.dialogVisible = true
    },
    effective2() {
      if (Object.keys(this.currentData).length === 0 && this.multipleSelection.length === 0) {
        this.$message.error('请选择需要签订的托运信息！')
        return
      }
      if (this.multipleSelection.length !== 0) {
        if (this.multipleSelection.length !== 1) {
          this.$message.error('请选择一条需要签订的托运信息！')
          return
        }
        this.currentData = this.multipleSelection[0]
      }

      if (
        this.currentData.cmtContractState != '0' &&
        this.currentData.cmtContractState != '3' &&
        this.currentData.cmtContractState != '4' &&
        this.currentData.cmtContractState != '5' &&
        this.currentData.cmtContractState != '6'
      ) {
        this.$message.error('请选择未签订的托运信息！')
        return
      }
      if (this.jftype === 'HZ' || this.jftype === 'TC') {
        if (this.currentData.cmtContractState !== '3' && this.currentData.cmtIsthrid === 'Y') {
          this.$message.error('该合同待平台确定')
          return
        }
      }
      let row = this.currentData
      if (this.currentData.cmtLineIsSign == 'Y') {
        this.eContractSee = true
      }
      let gysprice = []
      queryBiddingInfoList({
        bidId: row.bidId,
        sugarId: row.sugarId,
        biddingEnd: 'Y', //查询前三名推荐结果
        reviewStatus: 'Y', //评审状态
        quotaStatus: 'Y', //配额状态
      }).then(res => {
        if (res.success == 1) {
          gysprice = res.data
          console.log(gysprice)
        }
      })

      // selectSysCompanyByFltName({ fltName: row.cmtPartyBName }).then(res => {
      //   this.fltType = res.msg
      //   //          console.log(this.fltType)
      // })
      // console.log(this.fltType)
      // if (this.fltType == 'GYS') {
      this.pricesee = true
      this.priceseeA = false
      // } else {
      //   this.pricesee = false
      //   this.priceseeA = false
      // }
      this.name = ''
      this.openDialog = true
      this.see = true

      this.qdsee = false
      this.filesee = false
      this.edit = true
      this.disabled = true

      getFileList({ pubId: this.currentData.cmtId, module: 'HT' }).then(res => {
        this.gridData = res.data
      })
      this.feeValue = row.bidName
      this.dialogForm = Object.assign({}, row)
      this.cmtPartyAName = row.cmtPartyAName
      this.cmtPartyBName = row.cmtPartyBName
      if (row.consignmentDetailedVOs.length <= 4) {
        this.tableDataheight = '-'
        this.tableDataArray = row.consignmentDetailedVOs
        return
      }

      this.tableDataArray = row.consignmentDetailedVOs.slice(0, 4)
      this.$nextTick(() => {
        this.tableDataArray.push(row.consignmentDetailedVOs.slice(4, 5)[0])
        this.tableDataheightFn()
        if (row.consignmentDetailedVOs.length > 5) {
          this.tableDataArray = row.consignmentDetailedVOs
        }
      })
    },
    effective3() {
      if (this.currentData.cmtPartyA === '-1' && this.currentData.cmtPartyB === '-1') {
        this.$message.error('平台与平台之间不能签订合同')
        return
      }
      if (this.currentData.cmtContractState == '3') {
        if (this.currentData.cmtLineIsSign !== 'Y') {
          this.$message.error('请签订纸质合同')
          return
        }
      }
      if (this.currentData.cmtContractState == '0' || this.currentData.cmtContractState == '3' || this.currentData.cmtContractState == '6') {
        let count = []
        let yqdcount = []
        let gys1 = ''
        let gys2 = ''
        let kh1 = ''
        let kh2 = ''
        let countNo1 = ''
        let countNo2 = ''
        let xname1 = ''
        let xname2 = ''
        for (let i = 0; i < this.tableData.length; i++) {
          if (
            this.currentData.cmtId !== this.tableData[i].cmtId &&
            this.currentData.bidId === this.tableData[i].bidId &&
            this.currentData.sugarId === this.tableData[i].sugarId &&
            this.currentData.cmtPartyB === this.tableData[i].cmtPartyB &&
            this.currentData.bqId === this.tableData[i].bqId &&
            this.tableData[i].cmtContractState != '0' &&
            this.tableData[i].cmtContractState != '6'
          ) {
            if (this.currentData.cmtPartyA === this.tableData[i].cmtPartyA) {
              for (let j = 0; j < this.tableData.length; j++) {
                if (this.currentData.cmtContractMainno !== null) {
                  if (this.currentData.cmtContractMainno == this.tableData[j].cmtContractNo) {
                    gys1 = this.tableData[j].cmtPartyB
                  }
                } else if (
                  this.currentData.cmtContractNo.substring(0, 4) + 'KH' + this.currentData.cmtContractNo.substring(4) ==
                  this.tableData[j].cmtContractNo
                ) {
                  kh1 = this.tableData[j].cmtPartyA
                }
              }
              for (let k = 0; k < this.tableData.length; k++) {
                if (this.tableData[i].cmtContractMainno !== null) {
                  if (this.tableData[i].cmtContractMainno == this.tableData[k].cmtContractNo) {
                    gys2 = this.tableData[k].cmtPartyB
                  }
                } else if (
                  this.tableData[i].cmtContractNo.substring(0, 4) + 'KH' + this.tableData[i].cmtContractNo.substring(4) ==
                  this.tableData[k].cmtContractNo
                ) {
                  kh2 = this.tableData[k].cmtPartyA
                }
              }
              if (gys1 != '' && gys2 != '') {
                if (gys1 == gys2) {
                  yqdcount.push(this.tableData[i])
                  xname1 = this.currentData.cmtPartyAName
                  countNo1 = this.tableData[i].cmtContractNo
                }
              }
              if (kh1 != '' && kh2 != '') {
                if (kh1 == kh2) {
                  count.push(this.tableData[i])
                  xname2 = this.currentData.cmtPartyBName
                  countNo2 = this.tableData[i].cmtContractNo
                }
              }
            }
          }
        }

        if (yqdcount.length >= 1) {
          this.$message.error(xname1 + '已签订' + countNo1 + '合同')
          return
        }
        if (count.length >= 1) {
          this.$message.error(xname2 + '已签订' + countNo2 + '合同')
          return
        }
      }
      lineSign({ id: this.currentData.cmtId, fltCode: this.fltCode }).then(res => {
        this.$message({
          type: 'success',
          message: '签订成功！',
          showClose: true,
        })
        this.openDialog = false
        this.refreshList()
      })
    },

    effective() {
      // if (this.currentData.cmtContractState == '3') {
      //   if (this.currentData.cmtLineIsSign === 'Y') {
      //     this.$message.error('请签订电子合同')
      //     return
      //   }
      // }
      try {
        if (this.gridData.length === 0) {
          this.$message.error('请上传合同签章')
          return
        }
        try {
          if (this.currentData.cmtContractState == '0' || this.currentData.cmtContractState == '6') {
            if (this.gridData.length !== 0) {
              let filecount = 0
              for (let index = 0; index < this.gridData.length; index++) {
                if (this.gridData[index].acreate === store.state.user.USR_CODE_DX_H) {
                  filecount++
                }
              }
              if (filecount === 0) {
                this.$message.error('当前还未上传合同签章')
                return
              }
            }
          }
          if (this.currentData.cmtContractState == '3') {
            if (this.gridData.length === 1 && this.gridData[0].acreate !== store.state.user.USR_CODE_DX_H) {
              console.log(store.state.user.USR_CODE_DX_H)
              this.$message.error('请上传上传一份合同')
              return
            }
            if (this.gridData.length === 2 && this.gridData[1].acreate === this.gridData[0].acreate) {
              console.log(store.state.user.USR_CODE_DX_H)
              this.$message.error('只能上传一份合同')
              return
            }
            if (this.gridData.length > 2 && this.gridData[0].acreate !== store.state.user.USR_CODE_DX_H) {
              console.log(store.state.user.USR_CODE_DX_H)
              this.$message.error('只能上传一份合同')
              return
            }
          }
        } catch (error) {
          console.log(error)
        }
        if (this.currentData.cmtPartyA === '-1' && this.currentData.cmtPartyB === '-1') {
          this.$message.error('平台与平台之间不能签订合同')
          return
        }

        if (this.currentData.cmtContractState == '0' || this.currentData.cmtContractState == '3' || this.currentData.cmtContractState == '6') {
          let count = []
          let yqdcount = []
          let gys1 = ''
          let gys2 = ''
          let kh1 = ''
          let kh2 = ''
          let countNo1 = ''
          let countNo2 = ''
          let xname1 = ''
          let xname2 = ''
          for (let i = 0; i < this.tableData.length; i++) {
            if (
              this.currentData.cmtId !== this.tableData[i].cmtId &&
              this.currentData.bidId === this.tableData[i].bidId &&
              this.currentData.sugarId === this.tableData[i].sugarId &&
              this.currentData.cmtPartyB === this.tableData[i].cmtPartyB &&
              this.currentData.bqId === this.tableData[i].bqId &&
              this.tableData[i].cmtContractState != '0' &&
              this.tableData[i].cmtContractState != '6'
            ) {
              if (this.currentData.cmtPartyA === this.tableData[i].cmtPartyA) {
                for (let j = 0; j < this.tableData.length; j++) {
                  if (this.currentData.cmtContractMainno !== null) {
                    if (this.currentData.cmtContractMainno == this.tableData[j].cmtContractNo) {
                      gys1 = this.tableData[j].cmtPartyB
                    }
                  } else if (
                    this.currentData.cmtContractNo.substring(0, 4) + 'KH' + this.currentData.cmtContractNo.substring(4) ==
                    this.tableData[j].cmtContractNo
                  ) {
                    kh1 = this.tableData[j].cmtPartyA
                  }
                }
                for (let k = 0; k < this.tableData.length; k++) {
                  if (this.tableData[i].cmtContractMainno !== null) {
                    if (this.tableData[i].cmtContractMainno == this.tableData[k].cmtContractNo) {
                      gys2 = this.tableData[k].cmtPartyB
                    }
                  } else if (
                    this.tableData[i].cmtContractNo.substring(0, 4) + 'KH' + this.tableData[i].cmtContractNo.substring(4) ==
                    this.tableData[k].cmtContractNo
                  ) {
                    kh2 = this.tableData[k].cmtPartyA
                  }
                }
                if (gys1 != '' && gys2 != '') {
                  if (gys1 == gys2) {
                    yqdcount.push(this.tableData[i])
                    xname1 = this.currentData.cmtPartyAName
                    countNo1 = this.tableData[i].cmtContractNo
                  }
                }
                if (kh1 != '' && kh2 != '') {
                  if (kh1 == kh2) {
                    count.push(this.tableData[i])
                    xname2 = this.currentData.cmtPartyBName
                    countNo2 = this.tableData[i].cmtContractNo
                  }
                }
              }
            }
          }

          if (yqdcount.length >= 1) {
            this.$message.error(xname1 + '已签订' + countNo1 + '合同')
            return
          }
          if (count.length >= 1) {
            this.$message.error(xname2 + '已签订' + countNo2 + '合同')
            return
          }
        }
        effective(this.currentData.cmtId, this.dialogForm.cmtTransportUnitPrice).then(ref => {
          if (ref.success === '1') {
            this.$message({
              type: 'success',
              message: '签订成功！',
              showClose: true,
            })
            this.openDialog = false
            this.refreshList()
          }
        })
      } catch (error) {
        console.log(error)
      }
    },
    //打印  printMe 要打印内容的id
    printContent() {
      let subOutputRankPrint = document.getElementById('printMe')
      let childDiv = subOutputRankPrint.getElementsByTagName('div')[0].getElementsByTagName('p')
      let childDivA = subOutputRankPrint.getElementsByTagName('div')[0]
      childDivA.style.marginLeft = '70px'
      childDivA.style.marginTop = '60px'
      for (var i = 0; i < childDiv.length; i++) {
        // childDiv[i].style.marginLeft = '-35px'
        childDiv[i].style.lineHeight = '20px'
        // childDiv[i].style.fontSize = '30px'
        // console.log(childDiv[i],8888)
      }
      let newContent = subOutputRankPrint.innerHTML
      let oldContent = document.body.innerHTML
      document.body.innerHTML = newContent

      window.print()
      window.location.reload()
      document.body.innerHTML = oldContent
      this.downloadOpenDialog = false
      return false
    },
    download() {
      let _this = this
      this.$refs.dialogDownloadForm.validate(valid => {
        if (valid) {
          if (this.downloadType == 'html') {
            downloadContractHtmlModel({
              cmtId: this.currentData.cmtId,
              cteId: this.dialogDownloadForm.templateTvalue,
            }).then(res => {
              this.html = res.data.body

              this.downloadWidth = '50%'
              this.downloadType = 'template'
              this.$nextTick(() => {
                let subOutputRankPrint = document.getElementById('printMe')
                let childDiv = subOutputRankPrint.getElementsByTagName('div')[0].getElementsByTagName('p')
                let childDivA = subOutputRankPrint.getElementsByTagName('div')[0]
                childDivA.style.marginLeft = '70px'
                childDivA.style.marginTop = '60px'
                for (var i = 0; i < childDiv.length; i++) {
                  // childDiv[i].style.marginBottom = '5px'
                  // childDiv[i].style.marginLeft = '-35px'
                  childDiv[i].style.lineHeight = '20px'
                }
                let height = _this.$refs.html_template.offsetHeight * 0.9
                _this.templateObjec.height = height + 'px'
              })
            })
            return
          }
          for (let index = 0; index < this.multipleSelection.length; index++) {
            let id = this.multipleSelection[index].cmtId
            downloadContractModel({
              cmtId: id,
              cteId: this.dialogDownloadForm.templateTvalue,
            }).then(res => {
              let filename = res.headers['filename']
              filename = this.multipleSelection[index].cmtContractNo + decodeURI(filename)
              let blob = new Blob([res.data])
              let reader = new FileReader()
              reader.readAsDataURL(blob)
              reader.onload = e => {
                let a = document.createElement('a')
                a.download = filename
                a.href = e.target.result
                document.body.appendChild(a)
                a.click()
                document.body.removeChild(a)
              }
              window.parent._$store.dispatch('app/loading_status', false)
              this.closeDownload()
            })
          }
        }
      })
    },
    downloadDialog(type) {
      this.downloadWidth = '40%'
      this.downloadType = type
      let nametype = '下载'
      this.name = '合同下载'
      if (this.downloadType == 'html') {
        nametype = '打印'
        this.name = '合同打印'
      }
      if (Object.keys(this.currentData).length === 0 && this.downloadType === 'html') {
        this.$alert(`请选择需要的${nametype}合同！`, '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      if (this.multipleSelection.length === 0 && this.downloadType !== 'html') {
        this.$alert(`请选择需要的${nametype}合同！`, '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      findContractTemplateModel({}).then(ref => {
        this.templateList = ref.data
        this.downloadOpenDialog = true
      })
    },
    addDataArray() {
      let contractSugarTemporary = this.contractSugarTemporary || {}
      let quotaDialog = this.quotaDialog || {}
      let biddingTemporary = this.biddingTemporary || {}
      this.tableDataArray.push({
        // cddQuantity:contractSugarTemporary.transportQuantity||'',
        cddQuantity: quotaDialog.bqTransportQuantity || '',
        cddBrand: contractSugarTemporary.brand,
      })
      this.tableDataheightFn()
      this.$nextTick(() => {
        if (this.tableDataArray.length >= 5) {
          this.$refs.table_config_data_table.bodyWrapper.scrollTop = this.$refs.table_config_data_table.bodyWrapper.scrollHeight
        }
      })
    },
    tableDataheightFn() {
      if (this.tableDataArray.length == 5) {
        let table = this.$refs.table_config_data_table.$el
        this.tableDataheight = table.getElementsByTagName('table')[1].scrollHeight + table.getElementsByTagName('table')[0].scrollHeight
      }
    },
    //查询
    search() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.refreshList()
        }
      })
    },
    tableRowClassName({ row, rowIndex }) {
      row.rowIndex = rowIndex
    },
    rowData(row, column, event) {
      this.rowDataArray = row
    },
    delRow() {
      if (Object.keys(this.rowDataArray).length === 0) {
        this.$alert('请选择需要删除的托运信息！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      this.tableDataArray.splice(this.rowDataArray.rowIndex, 1)
      if (this.tableDataArray.length <= 5) {
        this.tableDataheight = '-'
      }
    },
    //双击查看啊详情
    dbrowClick(row) {
      this.openDialog = true
      this.currentData = Object.assign({}, row)
      if (this.currentData.cmtLineIsSign == 'Y') {
        this.eContractSee = true
      }
      this.see = true
      this.pricesee = true
      this.qdsee = true
      this.filesee = false
      this.edit = true
      this.disabled = true
      this.feeValue = row.bidName
      this.dialogForm = Object.assign({}, row)
      this.cmtPartyAName = row.cmtPartyAName
      this.cmtPartyBName = row.cmtPartyBName
      if (row.consignmentDetailedVOs.length <= 4) {
        this.tableDataheight = '-'
        this.tableDataArray = row.consignmentDetailedVOs
        return
      }
      this.tableDataArray = row.consignmentDetailedVOs.slice(0, 4)
      this.$nextTick(() => {
        this.tableDataArray.push(row.consignmentDetailedVOs.slice(4, 5)[0])
        this.tableDataheightFn()
        if (row.consignmentDetailedVOs.length > 5) {
          this.tableDataArray = row.consignmentDetailedVOs
        }
      })
    },
    //单击行
    rowClick(row) {
      this.currentData = Object.assign({}, row)
      this.$refs.multipleTable.toggleRowSelection(row)
      this.mainBotTableData = this.currentData.consignmentDetailedVOs
    },
    //删除车辆
    delCar() {
      if (Object.keys(this.currentData).length === 0) {
        this.$alert('请选择需要删除的合同！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      if (this.currentData.cmtContractState != '0') {
        this.$alert('合同生效禁止删除！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      this.$confirm('您确定要删除该合同吗？', '提示', {
        confirmButtonText: '确定',
      }).then(() => {
        delContractModel({ cmtId: this.currentData.cmtId }).then(res => {
          if (res.success === '1') {
            this.$message({
              type: 'success',
              message: '删除成功',
              showClose: true,
            })
            this.close()
          }
        })
      })
    },
    //保存
    save() {
      let _this = this
      _this.$refs.dialogForm.validate(valid => {
        if (Object.keys(this.tableDataArray).length != 0) {
          if (valid) {
            _this.$refs.tableDataArray.validate(valid => {
              if (valid) {
                _this.dialogForm.consignmentDetailedList = _this.tableDataArray
                if (this.edit) {
                  //编辑
                  editContractModel(_this.dialogForm).then(res => {
                    if (res.success === '1') {
                      this.$message({
                        type: 'success',
                        message: '编辑合同成功！',
                        showClose: true,
                      })
                      this.close()
                    }
                  })
                } else {
                  //新增a
                  let PartyA = _this.dialogForm.cmtPartyA
                  let PartyAName = _this.cmtPartyAName
                  let cmtPartyAContacts = _this.dialogForm.cmtPartyAContacts
                  let cmtPartyAPhone = _this.dialogForm.cmtPartyAPhone

                  if (_this.dialogForm.cmtIsthrid == 'Y') {
                    _this.dialogForm.cmtPartyA = '-1'
                    _this.dialogForm.cmtPartyAName = '广西泛糖科技有限公司'
                    _this.dialogForm.cmtPartyAContacts = '李翠芳'
                    _this.dialogForm.cmtPartyAPhone = '18260866919'
                    // _this.dialogForm.cmtPartyB = '-1'
                    // _this.dialogForm.cmtPartyBName = '泛糖科技'
                  }
                  addContractModel(_this.dialogForm).then(res => {
                    if (res.success === '1') {
                      if (_this.dialogForm.cmtIsthrid != 'Y') {
                        this.$message({
                          type: 'success',
                          message: '新增合同成功！',
                          showClose: true,
                        })
                        this.close()
                      }
                    }
                  })
                  try {
                    if (_this.dialogForm.cmtIsthrid == 'Y') {
                      _this.dialogForm.cmtContractMainno = _this.dialogForm.cmtContractNo
                      _this.dialogForm.cmtContractNo = _this.dialogForm.cmtContractNo.substring(0, 4) + 'KH' + _this.dialogForm.cmtContractNo.substring(4)
                      _this.dialogForm.cmtPartyA = PartyA
                      _this.dialogForm.cmtPartyAName = PartyAName
                      _this.dialogForm.cmtPartyAContacts = cmtPartyAContacts
                      _this.dialogForm.cmtPartyAPhone = cmtPartyAPhone
                      _this.dialogForm.cmtPartyB = '-1'
                      _this.dialogForm.cmtPartyBName = '广西泛糖科技有限公司'
                      _this.dialogForm.cmtPartyBContacts = '李翠芳'
                      _this.dialogForm.cmtPartyBPhone = '18260866919'
                      // //设置公司名称
                      _this.dialogForm.cmtCorporateName = '广西泛糖科技有限公司'
                      // //设置开户行
                      _this.dialogForm.cmtOpeningBank = '中国建设银行（南宁新城支行）'
                      // //设置账号
                      _this.dialogForm.cmtAccount = '45050160425500000619'
                      // _this.dialogForm.cmtPartyA = '-1'
                      // _this.dialogForm.cmtPartyAName = '泛糖科技'
                      // contractGenerateNo({
                      //   cmtPartyA: _this.dialogForm.cmtPartyA
                      // }).then(res => {
                      // _this.dialogForm.cmtContractNo = res.data
                      addContractModel(_this.dialogForm).then(res => {
                        if (res.success === '1') {
                          this.$message({
                            type: 'success',
                            message: '新增合同成功！',
                            showClose: true,
                          })
                          this.close()
                        }
                      })
                      // })
                    }
                  } catch (error) {
                    console.log(error)
                  }
                }
              }
            })
          }
        } else {
          this.$alert('输入托运信息才能保存', '提示', {
            confirmButtonText: '确定',
          })
        }
      })
    },

    computingBrandCache(arryData) {
      if (!(arryData instanceof Array) || arryData.length == 0) {
        return
      }
      let contractSugarTemporary = this.contractSugarTemporary || {}
      let map = arryData.reduce((m, x) => m.set(x.cddBrand, (m.get(x.cddBrand) || 0) + 1), new Map())
      let newarry = Array.from(map.values()).sort((a, b) => b - a)
      if (newarry[0] == 1 || newarry.length == 1) {
        contractSugarTemporary.brand = arryData[newarry.length - 1].cddBrand
        this.contractSugarTemporary = contractSugarTemporary
        return
      }
      let cddBrandArry = []
      map.forEach((v, k) => {
        if (v == newarry[0]) {
          cddBrandArry.push(k)
        }
      })
      let cddBrand = null
      if (cddBrandArry.length == 1) {
        cddBrand = cddBrandArry[0]
      } else {
        for (var i = cddBrandArry.length - 1; i >= 0; i--) {
          if (cddBrandArry.indexOf(cddBrandArry[i].cddBrand) != -1) {
            cddBrand = cddBrandArry[i].cddBrand
            return
          }
        }
      }
      contractSugarTemporary.brand = cddBrand
      this.contractSugarTemporary = contractSugarTemporary
    },
    //编辑车辆
    editCar() {
      findjfang().then(res => {
        if (res.success == '1') {
          this.jfdropdown = res.data
        }
      })
      findefang().then(res => {
        if (res.success == '1') {
          this.efdropdown = res.data
        }
      })
      //1.先判断是否已审核 2.执行编辑
      if (Object.keys(this.currentData).length === 0) {
        this.$alert('请选择需要编辑的合同！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      if (this.currentData.cmtContractState != '0' && this.currentData.cmtContractState != '6') {
        this.$alert('合同生效禁止编辑！', '提示', {
          confirmButtonText: '确定',
        })
        return
      }
      // if (this.currentData.cmtPartyA !== '-1') {
      //   if (this.currentData.cmtIsthrid == 'Y') {
      //     this.$alert('已存在第三方不支持编辑', '提示', {
      //       confirmButtonText: '确定'
      //     })
      //     return
      //   }
      // }

      // if (this.currentData.cmtIsthrid == 'Y') {
      //   this.see = true
      //   this.pricesee = false
      // } else {
      //   this.see = false
      //   this.pricesee = false
      // }
      this.see = false
      this.pricesee = false
      this.priceseeA = true
      this.openDialog = true
      this.edit = true
      this.qdsee = true
      this.filesee = true
      this.disabled = true
      this.name = '编辑合同管理'
      this.dialogForm = this.currentData
      this.feeValue = this.currentData.bidName
      this.cmtPartyAName = this.currentData.cmtPartyAName
      this.cmtPartyBName = this.currentData.cmtPartyBName

      this.computingBrandCache(this.currentData.consignmentDetailedVOs)
      if (this.currentData.consignmentDetailedVOs.length <= 4) {
        this.tableDataheight = '-'
        this.tableDataArray = this.currentData.consignmentDetailedVOs
        return
      }
      this.tableDataArray = this.currentData.consignmentDetailedVOs.slice(0, 4)
      this.$nextTick(() => {
        this.tableDataArray.push(this.currentData.consignmentDetailedVOs.slice(4, 5)[0])
        this.tableDataheightFn()
        if (this.currentData.consignmentDetailedVOs.length > 5) {
          this.tableDataArray = this.currentData.consignmentDetailedVOs
        }
      })
    },
    //新增车辆
    addCar() {
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].consignmentDetailedVOs.length > 0) {
          this.goodarr.push(this.tableData[i].consignmentDetailedVOs[0])
        }
      }
      const res = new Map()
      this.goodarr = this.goodarr.filter(a => !res.has(a.cddGrade) && res.set(a.cddGrade, 1))
      dropdownsh({ param: 'cmt_consignee_information' }).then(res => {
        this.mddslist = res.data
      })
      dropdownsh({ param: 'cmt_receiving_contact' }).then(res => {
        this.shlxrlist = res.data
      })
      dropdownsh({ param: 'cmt_receiving_phone' }).then(res => {
        this.lxrphonelist = res.data
      })
      this.openDialog = true
      this.see = false
      this.pricesee = false
      this.priceseeA = true
      this.edit = false
      this.qdsee = true
      this.disabled = false
      this.filesee = true
      this.name = '新增合同管理'
      this.tableDataArray = []
      this.tableDataArray.push({
        cddTakeNo: '',
        cddShippingCompany: '',
        cddQuantity: '',
        cddGrade: '',
        cddBrand: '',
      })
      this.feeValue = ''
      this.tableDataheight = '-'
      this.dialogForm = {
        cmtIsthrid: 'Y',
        cmtContractTotalTransport: 0,
        cmtContractNo: '',
        cmtContractType: 'Logistics',
        cmtContractName: '货运平台运输委托合同',
        cmtPartyA: '',
        cmtPartyAContacts: '',
        cmtPartyAPhone: '',
        cmtPartyB: '',
        cmtPartyBContacts: '',
        cmtPartyBPhone: '',
        cmtConsigneeInformation: '',
        cmtPlaceReceipt: '',
        cmtReceivingContact: '',
        cmtReceivingPhone: '',
        cmtLoadingPlace: '',
        cmtLoadingContact: '',
        cmtGoodsName: '',
        cmtPackingMethod: '',
        cmtSingleWeight: '',
        cmtShippingType: '',
        cmtTransportUnitPrice: '',
        cmtTotalFreight: '',
        cmtStartDateShipment: '',
        cmtLatestLoadingDate: '',
        cmtCorporateName: '',
        cmtOpeningBank: '',
        cmtAccount: '',
      }
      findjfang().then(res => {
        if (res.success == '1') {
          this.jfdropdown = res.data
        }
      })
      findefang().then(res => {
        if (res.success == '1') {
          this.efdropdown = res.data
        }
      })
    },
    closeDownload() {
      console.log(1111)
      this.downloadOpenDialog = false
      this.refreshList()
    },
    //关闭车辆对话框
    close() {
      this.openDialog = false
      this.eContractSee = false
      this.$refs.dialogForm.resetFields()
      this.goodarr = []
      this.currentData = {}
      this.refreshList()
    },
    getShippingTypeList() {
      getRefCodesByType('运输类型').then(res => {
        this.shippingType = res.data
      })
    },
  },
  watch: {
    tableDataArray: function () {
      this.calculation
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep .splitter-pane-resizer.horizontal {
  margin-top: -15px;
}
.danger {
  color: #f56c6c;
}
.app-container {
  overflow: hidden;
  background-color: #fff;
  position: relative;
  height: 100%;
}
.tree {
  padding-right: 20px;
  font-size: 1.4rem;
}
.right-detail {
  height: 100%;
  .top-type {
    width: 100%;
    height: 100%;
    table {
      max-width: 100%;
      font-size: 1.4rem;
    }
  }
  .bottom-code {
    width: 100%;
    height: 100%;
  }
}
.codeNumberCode {
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 28px;
}
// 弹窗内的样式
.dialogBox {
  width: 100%;
  height: 100%;

  .box {
    padding: 12px 12px 1px 12px;
    position: relative;
    border: 1px solid rgb(29, 158, 233);
    border-radius: 5px;
    // height:300px;
    margin-bottom: 20px;
    .grid-content {
      height: 44px;
    }
    .name {
      position: absolute;
      top: -20px;
      font-size: 16px;
      font-weight: 700;
      padding: 10px;
      line-height: 20px;
      background: #fff;
    }
  }
  .dialogTopBox {
    width: 100%;
    padding-top: 20px;
    .botTitl {
      font-size: 18px;
      padding: 0px 0 5px 10px;
    }
  }
  .pointerinput {
    ::v-deep .el-input__inner {
      cursor: pointer;
      background-color: #fff;
      color: #606266;
    }
  }
  .dialogBotBox {
    margin-top: 10px;
    .botTitl {
      font-size: 18px;
      padding: 0px 0 5px 10px;
    }

    .botBtnBox {
      padding-left: 5px;
      padding-top: 1px;
      padding-bottom: 3px;
    }

    ::v-deep .solveDetailTable {
      padding-top: 5px;

      .el-input__inner {
        padding: 0;
      }

      .cell.el-tooltip {
        padding: 0;
      }
    }
  }
}

.pic {
  height: 500px;
  overflow: auto;
  img {
    width: 100%;
  }
}

div {
  ::v-deep .el-dialog__body {
    padding-bottom: 0px;
    padding-top: 1px;
  }
  .el-divider {
    background-color: white;
    position: relative;
  }
}
.driver {
  width: 100%;
  height: 100%;
  padding: 15px 15px 12px;
  display: flex;
  flex-direction: column;
  .form {
    height: 30px;
  }
  .btn {
    height: 50px;
    line-height: 50px;
  }
  .name {
    font-size: 16px;
    line-height: 20px;
    font-weight: 500;
  }
  .table {
    flex: 1;
  }
  .pages {
    height: 30px;
  }

  .box {
    //上传对话框
    overflow: hidden;
    height: 200px;
    .selectItem {
      // float:right;
      display: inline-block;
      width: 50%;
      height: 100%;
      box-sizing: border-box;
      padding: 20px;
    }
    .upload {
      // float:right;
      display: inline-block;
      width: 50%;
      height: 100%;
      box-sizing: border-box;
      padding: 20px;
    }
  }
}
</style>
